How To Create Simple Login Page In Html

How To Articles

Welcome to my article on how to create a simple login page in HTML. As a web developer, I have often found the need to create login pages for my websites. In this article, I will guide you through the process of creating a basic login page using HTML. So, let’s get started!

Step 1: Setting up the HTML Structure

The first step in creating a login page is to set up the basic HTML structure. We will start by creating a new HTML file and adding the necessary tags. Here’s a sample code:

<!DOCTYPE html>
<h2>Login Page</h2>
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>

<label for="password">Password:</label>
<input type="password" id="password" name="password"><br>

<input type="submit" value="Login">

In the above code, we have defined a simple form with two input fields – one for the username and one for the password. We have also added a submit button to allow users to login.

Step 2: Adding CSS Styling

To make our login page visually appealing, we can add some CSS styling. Here’s an example:

body {
font-family: Arial, sans-serif;
background-color: #f1f1f1;

h2 {
color: #333;

form {
background-color: #fff;
padding: 20px;
width: 300px;
margin: 0 auto;
border: 1px solid #ddd;

label {
display: block;
margin-bottom: 10px;

input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
margin-bottom: 20px;

input[type="submit"] {
background-color: #4caf50;
color: #fff;
border: none;
padding: 10px 20px;
cursor: pointer;


The above CSS code adds some basic styling to our login page. Feel free to customize the styling according to your preferences.

Step 3: Adding Functionality with JavaScript

To make the login page functional, we can add some JavaScript code to handle the form submission and validate user input. Here’s an example:

function validateForm() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;

if (username === "" || password === "") {
alert("Please enter a username and password.");
return false;

// Perform further validation or submit the form

In the above JavaScript code, we have defined a function validateForm that checks if the username and password fields are empty. If they are empty, an alert message is displayed. You can add more complex validation logic or submit the form to a server if needed.


Creating a simple login page in HTML is a fundamental skill for web developers. By following the steps outlined in this article, you can easily create your own basic login page. Remember to customize the design and add any additional functionality required for your specific application. Feel free to experiment and add your personal touches to make the login page uniquely yours. Happy coding!