Build a login form

Task

The starter page has a sign-in form with typical mistakes: no method, the password typed in a plain text field, placeholders instead of labels and an "OK" button. Fix it so that password managers can fill it in and every field is clearly labelled — no JavaScript.

Requirements

  • The form uses method="post", so the login and password never end up in the URL
  • The login field has a <label>, type="email", autocomplete="username" and required
  • The password field has a <label>, type="password", autocomplete="current-password" and required
  • A "Remember me" checkbox with its own <label>
  • A link to the password reset page (an <a> with an href) inside the form
  • A <button type="submit"> with clear text such as "Sign in"
  • No JavaScript, and no minlength or pattern on the password field

Starter code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Sign in</title>
</head>
<body>
  <h1>Sign in</h1>
  <form action="/login">
    <input type="text" name="login" placeholder="Email">
    <input type="text" name="password" placeholder="Password">
    <button>OK</button>
  </form>
</body>
</html>
▶ Open in HTML Editor

Hints

  • Without method="post" a form is sent with GET, and the login and password appear in the address bar and the browser history.
  • autocomplete="username" and autocomplete="current-password" tell password managers which saved account to fill in. A registration form uses autocomplete="new-password" instead.
  • type="password" only hides the characters on screen. It does not encrypt anything — the site must use HTTPS.
  • Don't add minlength or pattern to a login password: the user types an existing password, and password rules belong on the registration form.
  • A placeholder disappears as soon as typing starts, so keep a visible <label> for every field.
Show solution
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Sign in</title>
</head>
<body>
  <h1>Sign in</h1>
  <form action="/login" method="post">
    <label for="email">Email</label>
    <input type="email" id="email" name="email" autocomplete="username" required>

    <label for="password">Password</label>
    <input type="password" id="password" name="password" autocomplete="current-password" required>
    <a href="/forgot-password">Forgot your password?</a>

    <input type="checkbox" id="remember" name="remember">
    <label for="remember">Remember me</label>

    <button type="submit">Sign in</button>
  </form>
</body>
</html>

Related tools