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
HTML Form Generator
Add text, email, phone, password, select, checkbox or radio fields and get ready HTML form code with proper labels and built-in validation.
HTML Editor Online
Write HTML with syntax highlighting and line numbers, see a live preview, format or minify it, and open or save .html files — all in your browser.
Build a registration form with built-in validation
Practice exercise: build a course sign-up form with fieldset, input types, required, pattern and minlength — validation without JavaScript.
Build a contact form
Practice exercise: build a contact form with name, email, and message fields.
Forms
form, input, label, button — the basic building blocks of a data-entry form.
The <form> tag
The action, method, and enctype attributes of the <form> tag, with an example.
The <input> tag
Types and attributes of the <input> tag: type, name, value, required, pattern.
The type attribute
The type attribute for input (text/number/checkbox etc.), button, and script (script type).
The required attribute
The boolean required attribute for input, select, textarea: built-in HTML5 required-field validation.
HTML Validator
Check HTML for unclosed tags, duplicate ids, and other errors with the Nu Html Checker. Your code is sent to our server for checking.