How To Make Login Page In Html Code

HTML Programming

In this article, I will guide you on how to create a login page using HTML code. As a web developer, I know how important it is to have a secure and user-friendly authentication system for any website. By following the steps below, you will be able to create your own login page in no time!

Step 1: Creating the HTML Structure

The first step in creating a login page is to set up the HTML structure. We will start by creating a form element that will contain our login fields. Here is an example:

<label for="username">Username:</label>
<input type="text" id="username" name="username">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<input type="submit" value="Login">

In the above code, we have created two input fields, one for the username and another for the password. We have also included a submit button labeled “Login”. Feel free to customize the form elements according to your preferences.

Step 2: Styling the Login Page

Once we have the basic HTML structure in place, it’s time to add some CSS styles to make our login page visually appealing. You can add your own personal touches and creativity to make it unique. Here is an example of some CSS styles you can use:

form {
width: 300px;
margin: 0 auto;
padding: 20px;
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 5px;

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

input[type="password"] {
width: 100%;
padding: 5px;
margin-bottom: 10px;

input[type="submit"] {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;

The above CSS code will give your login form a clean and modern look. Feel free to experiment with different colors, fonts, and layout options to match your website’s overall design.

Step 3: Adding Functionality with JavaScript

Now that we have our HTML structure and CSS styles in place, it’s time to add some functionality to our login page. We can achieve this by using JavaScript. Here is an example of how we can validate the login credentials:

let form = document.querySelector('form');
let usernameInput = document.querySelector('#username');
let passwordInput = document.querySelector('#password');

form.addEventListener('submit', function(event) {

let username = usernameInput.value;
let password = passwordInput.value;

if (username === 'admin' && password === 'password') {
alert('Login successful!');
// You can redirect the user to another page here
} else {
alert('Invalid username or password. Please try again.');

In the above JavaScript code, we are listening for the form’s submit event. When the user submits the form, we get the values entered in the username and password fields. We then validate these credentials and display an alert message accordingly. You can also redirect the user to another page upon successful login.


By following the steps outlined in this article, you can create a login page using HTML, CSS, and JavaScript. Remember to keep security in mind and implement additional measures such as password hashing and server-side validation for a robust authentication system. Feel free to add your own personal touches to make your login page unique and user-friendly.