HTML Login Form Template
A login form asks for a username (or email) and a password. This template is simple and clean, and the browser checks the required fields.
HTML and CSS code
<style>
.login-form { max-width: 320px; font-family: Arial, sans-serif; border: 1px solid #ccc; padding: 20px; border-radius: 6px; }
.login-form label { display: block; margin: 10px 0 4px; }
.login-form input[type="text"], .login-form input[type="password"] {
width: 100%; padding: 8px; box-sizing: border-box;
}
.login-form button { margin-top: 14px; width: 100%; padding: 10px; background: #0073aa; color: #fff; border: 0; border-radius: 4px; }
</style>
<form class="login-form" action="login.php" method="post">
<h2>Login</h2>
<label for="user">Username</label>
<input type="text" id="user" name="username" required autofocus>
<label for="pass">Password</label>
<input type="password" id="pass" name="password" required>
<label><input type="checkbox" name="remember"> Remember me</label>
<button type="submit">Log in</button>
</form>
Output in the browser:
Output in the browser
Note:
This is only the front part. Checking the password must be done on the server. Use the POST method, HTTPS, and store passwords hashed. See our PHP login and registration script.
Learn more about the similar topics:
| Tutorials |
|---|
| HTML Input Types |
| HTML Forms |
| Exercises & Assignments |
|---|
| Write an HTML program to create a registration form |
| Write an HTML program to create a contact form |
| Interview Questions & Answers |
|---|
| What are the different new form element types in HTML5? |
| What is the difference between GET and POST methods in an HTML form? |
| What is the use of the label tag in HTML? |