Create Beautiful Login Page Using HTML and JS

Hello Friend, In this tutorial we will learn to create beautiful login page using HTML and JavaScript:


<!DOCTYPE html>
<title>Beautiful Login Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
<div class="container">
<form class="login-form" action="" method="post">
<div class="input-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required>
<div class="input-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
<p class="message">Not registered? <a href="#">Create an account</a></p>
<script src="script.js"></script>


* {
box-sizing: border-box;
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #f2f2f2;
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
.login-form {
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
padding: 40px;
width: 400px;
h2 {
margin-top: 0;
.input-group {
margin-bottom: 20px;
label {
display: block;
font-weight: bold;
margin-bottom: 5px;
input[type="password"] {
padding: 10px;
width: 100%;
border-radius: 3px;
border: none;
box-shadow: 0px 0px 5px rgba(0,0,0,0.1);
button[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 3px;
cursor: pointer;
button[type="submit"]:hover {
background-color: #3e8e41;
.message {
margin-top: 20px;
font-size: 14px;
text-align: center;
.message a {
color: #4CAF50;
text-decoration: none;


const form = document.querySelector(".login-form");
const usernameInput = document.getElementById("username");
const passwordInput = document.getElementById("password");
form.addEventListener("submit", (event) => {
const usernameValue = usernameInput.value.trim();
const passwordValue = passwordInput.value.trim();
if (usernameValue === "" || passwordValue === "") {
alert("Please enter a username and password.");
} else {
// Login logic goes here

Note: This is just an example, you can modify the code to fit your specific requirements and design preferences.