
Login and registration forms are at the heart of most interactive websites, from social platforms to shopping sites. If you’re a beginner in web development, this is a perfect mini project to learn core concepts like form creation, layout design, and DOM manipulation.
In this blog, we’ll build a beautiful, responsive login and registration form using pure HTML, CSS, and JavaScript, with no libraries, no frameworks, and no backend. Just front-end magic.
If you are interested in login and registration form templates, we have designed a collection of pre-built forms. Check Formly, specially designed to help developers create stylish, responsive, and functional login forms effortlessly.
Step 1: HTML to Build the Structure
First, we’ll create a simple layout with two forms inside a container, one for login and one for registration.
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login & Register</title>
<link rel="stylesheet" href="style.css" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
</head>
<body>
<div class="wrapper">
<div class="form-box">
<div class="toggle-buttons">
<button id="loginBtn" class="active" onclick="showLogin()">Login</button>
<button id="registerBtn" onclick="showRegister()">Register</button>
</div>
<form id="loginForm" class="form active-form">
<h2>Welcome Back</h2>
<input type="text" placeholder="Username" required />
<input type="password" placeholder="Password" required />
<button type="submit">Login</button>
</form>
<form id="registerForm" class="form">
<h2>Create Account</h2>
<input type="text" placeholder="Username" required />
<input type="email" placeholder="Email" required />
<input type="password" placeholder="Password" required />
<button type="submit">Register</button>
</form>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Step 2: CSS to Add Style
Let’s design a clean and modern UI. Smooth gradients, shadows, and rounded corners make it visually appealing.
/* style.css */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #71b7e6, #9b59b6);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.wrapper {
background: #fff;
border-radius: 16px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
width: 350px;
padding: 30px;
transition: all 0.3s ease;
}
.form-box {
width: 100%;
}
.toggle-buttons {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.toggle-buttons button {
flex: 1;
padding: 10px;
border: none;
background: #f1f1f1;
cursor: pointer;
font-weight: 600;
transition: background 0.3s ease;
border-radius: 8px;
}
.toggle-buttons button.active {
background: #9b59b6;
color: white;
}
.form {
display: none;
flex-direction: column;
}
.form.active-form {
display: flex;
}
.form h2 {
margin-bottom: 20px;
color: #333;
}
.form input {
padding: 12px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 8px;
font-size: 14px;
}
.form button {
padding: 12px;
background: #9b59b6;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: background 0.3s ease;
}
.form button:hover {
background: #8c40aa;
}
@media (max-width: 400px) {
.wrapper {
width: 90%;
}
}
Step 3: JavaScript to Add Functionality
Now, we’ll add a simple script to smoothly toggle between the two forms.
// script.js
const loginBtn = document.getElementById("loginBtn");
const registerBtn = document.getElementById("registerBtn");
const loginForm = document.getElementById("loginForm");
const registerForm = document.getElementById("registerForm");
function showLogin() {
loginForm.classList.add("active-form");
registerForm.classList.remove("active-form");
loginBtn.classList.add("active");
registerBtn.classList.remove("active");
}
function showRegister() {
registerForm.classList.add("active-form");
loginForm.classList.remove("active-form");
registerBtn.classList.add("active");
loginBtn.classList.remove("active");
}
Final Thoughts
You’ve just created a fully functional and visually appealing login and registration form using only HTML, CSS, and JavaScript! This layout is perfect for integrating into any website or project.