Login & Signup System with HTML, CSS & JavaScript
30 DAYS 30 PROJECT CHALLENGE
Day #01
Project Overview
Login & Signup System is a simple beginner-friendly project that uses HTML, CSS, and JavaScript. The application provides Login and Sign Up forms within the same interface, allowing users to create an account and then log in with their saved details. Users can switch between the Sign Up and Login options without opening another page, tab, or window.
JavaScript validates the name, email, and password fields and displays helpful messages when users enter invalid information. Users can also show or hide their passwords while typing. The application handles form switching, validation, and browser-based data storage with JavaScript and LocalStorage. As a result, beginners can explore how a frontend application manages basic user interactions without requiring a server-side component or database.
Key Features
- Login/Signup Forms: The application provides both Login and Sign Up functionality within the same interface. Users can easily switch between the two forms without opening another page.
- Form Toggle Functionality: JavaScript dynamically changes the form title, button text, and toggle message when users switch between Login and Sign Up modes. The Full Name field is displayed only when creating a new account.
- Full Name Validation: The application checks whether users enter their full names during signup. If the field is empty, JavaScript displays an error message.
- Email Validation: JavaScript checks whether users enter a valid email address. The application displays an error message when the email field is empty or the entered email does not meet the required format.
- Password Length Validation: It ensures that the user supplies a secure password with at least six characters. This assists users in determining whether their passwords are appropriate for their accounts.
- The Show/Hide Password: Users can switch between hidden and visible password states while entering their password. This option makes it easier to check the typed password before submitting the form.
- LocalStorage-Based Signup: After successful signup, JavaScript saves the user’s details in LocalStorage for demonstration purposes. During login, the application retrieves the saved information and compares it with the entered details.
- Login Authentication: During login, JavaScript retrieves the saved user information from LocalStorage and compares it with the entered email and password.
- Account Availability Check: If a user attempts to log in before creating an account, the application displays a message asking them to sign up first.
- Success and Error Messages: It provides clear feedback after signup or login attempts. JavaScript displays success messages for completed actions and error messages when users enter incorrect or incomplete information.
- Reset Form Fields: JavaScript clears the form fields when users switch between Login and Sign Up modes. This prevents previously entered information from remaining visible in the form.
- Responsive User Interface: The Login & Signup System has a responsive design that works on different screen sizes. It uses a centered container and some simple responsive styling to provide a seamless experience on desktops, tablets, and phones.
What You'll Learn
- Understand how to create Login and Signup forms using HTML.
- Learn how to handle form submission with JavaScript.
- Practice preventing the default form submission behaviour.
- Know how to validate name, email, and password fields.
- Learn how conditional statements control different application states.
- Practice selecting and updating HTML elements using JavaScript.
- Learn how to switch between Login and Sign Up interfaces dynamically.
- Practice storing JavaScript objects in LocalStorage.
- Understand how
JSON.stringify()andJSON.parse()work. - Practice displaying success and error messages dynamically.
HTML Code
HTML creates the structure of the Login & Signup System. First, the style.css file is linked inside the <head> section so CSS can control the application’s appearance and layout. The .container element holds the form heading, input fields, submit button, success message, and the option for switching between Login and Sign Up modes. The <h2> element with the formTitle ID displays the current form title. Initially, it shows Login, and JavaScript changes the text when users switch to Sign Up mode.
Input Fields and Form Controls
The form uses the authForm ID. Inside the form, the nameGroup section contains the Full Name input and its error message. JavaScript keeps this section hidden during Login mode because only Sign Up requires a name. Users can always access the Email and Password fields because both forms require these details. Each field has a separate error element that JavaScript can display when validation fails. The password section also includes a Show Password option that calls the togglePassword() function and switches the password input between hidden and visible modes.
Additional Elements
The submit button uses the submitBtn ID, which allows JavaScript to change its text between Login and Sign Up, successMsg element displays successful signup or login messages. Finally, the page loads the script.js file at the bottom of the <body> so JavaScript can access the HTML elements and handle the required interactions.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login & Signup System</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<h2 id="formTitle">Login</h2>
<form id="authForm">
<div class="input-group" id="nameGroup">
<label>Full Name</label>
<input type="text" id="name" />
<div class="error" id="nameError">Name is required</div>
</div>
<div class="input-group">
<label>Email</label>
<input type="email" id="email" />
<div class="error" id="emailError">Enter a valid email</div>
</div>
<div class="input-group">
<label>Password</label>
<input type="password" id="password" />
<span class="password-toggle" onclick="togglePassword()">Show Password</span>
<div class="error" id="passwordError">
Password must be at least 6 characters
</div>
</div>
<button type="submit" id="submitBtn">Login</button>
<div class="success" id="successMsg"></div>
</form>
<div class="toggle">
<span id="toggleText">Don't have an account?</span>
<span class="toggle-link" id="toggleLink" onclick="toggleForm()">Sign Up</span>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS Code
CSS controls the appearance and layout of the Login & Signup System. The universal selector applies box-sizing: border-box and sets a consistent font family across the application. Flexbox in the body centers the form container on the screen. The min-height: 100vh property allows the layout to use the full browser height. Meanwhile, the background color creates contrast with the white form container. The .container class controls the main Login and Signup box by defining its width, padding, background, rounded corners, and box shadow.
Form Fields and Buttons
Each .input-group adds spacing between form fields. CSS places labels above their corresponding inputs and gives the input fields a full width layout with padding, borders, and rounded corners. The :focus selector changes the border color when users interact with an input. The .error class controls validation messages and keeps them hidden until JavaScript displays them. CSS also styles the submit button to fill the available width of the form.
Interactive Elements
The button hover effect provides visual feedback when users move the cursor over it. The .toggle and .toggle-link styles create the area that allows users to switch between Login and Sign Up modes, .success class controls the appearance of successful action messages, while .password-toggle makes the Show Password option look interactive. Finally, #nameGroup remains hidden by default, and JavaScript displays it when users switch to Sign Up mode.
* {
box-sizing: border-box;
font-family: "Segoe UI", sans-serif;
}
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #042453;
}
.container {
background: #ffffff;
width: 380px;
padding: 30px;
border-radius: 12px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}
h2 {
text-align: center;
margin-bottom: 20px;
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
font-size: 14px;
margin-bottom: 5px;
}
.input-group input {
width: 100%;
padding: 10px;
border-radius: 6px;
border: 1px solid #ccc;
outline: none;
}
.input-group input:focus {
border-color: #6366f1;
}
.error {
color: red;
font-size: 12px;
margin-top: 5px;
display: none;
}
button {
width: 100%;
padding: 12px;
background: #042453;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
}
button:hover {
background: #4338ca;
}
.toggle {
text-align: center;
margin-top: 15px;
font-size: 14px;
}
.toggle-link {
color: #4f46e5;
cursor: pointer;
font-weight: bold;
margin-left: 5px;
}
.success {
text-align: center;
color: green;
margin-top: 10px;
display: none;
}
.password-toggle {
font-size: 12px;
color: #4f46e5;
cursor: pointer;
margin-top: 5px;
display: inline-block;
}
#nameGroup {
display: none;
}
Javascript Code
Form Switching and Password Control
JavaScript provides the main functionality for the Login & Signup System. First, the code selects important HTML elements, including the form title, name field, submit button, toggle text, form, and success message. isSignup variable keeps track of whether the application currently displays the Login form or the Sign Up form and the toggleForm() function updates this value and changes the form accordingly. It updates the heading, submit button text, toggle message, and visibility of the Full Name field.
This togglePassword() function switches the password input type between password and text. Users can therefore hide or view their entered password when needed.
Form Validation and Data Storage
The clearErrors() function finds all elements with the .error class and hides them. This prevents old validation messages from remaining visible after users submit the form again. When users submit the form, JavaScript prevents the default page reload and reads the entered name, email, and password values. The validation process then checks whether the information meets the required conditions. During signup, users must enter a name, provide an email containing @, and create a password with at least six characters.
After successful validation, JavaScript stores the entered information as an object in LocalStorage. The JSON.stringify() method converts the JavaScript object into a string before LocalStorage saves it.
Login Verification
During login, JSON.parse() retrieves the saved user information and converts it back into a JavaScript object. The application then compares the entered email and password with the saved demonstration data. If both values match, JavaScript displays a welcome message. Otherwise, the application shows an error message. This project demonstrates how JavaScript can handle basic client-side authentication logic in a frontend learning project.
const formTitle = document.getElementById("formTitle");
const nameGroup = document.getElementById("nameGroup");
const submitBtn = document.getElementById("submitBtn");
const toggleText = document.getElementById("toggleText");
const toggleLink = document.getElementById("toggleLink");
const form = document.getElementById("authForm");
const successMsg = document.getElementById("successMsg");
let isSignup = false;
/* ---------------- TOGGLE FORM ---------------- */
function toggleForm() {
isSignup = !isSignup;
if (isSignup) {
formTitle.innerText = "Sign Up";
submitBtn.innerText = "Sign Up";
toggleText.innerText = "Already have an account?";
toggleLink.innerText = "Login";
nameGroup.style.display = "block";
} else {
formTitle.innerText = "Login";
submitBtn.innerText = "Login";
toggleText.innerText = "Don't have an account?";
toggleLink.innerText = "Sign Up";
nameGroup.style.display = "none";
}
clearErrors();
successMsg.style.display = "none";
form.reset();
}
/* ---------------- SHOW / HIDE PASSWORD ---------------- */
function togglePassword() {
const password = document.getElementById("password");
password.type = password.type === "password" ? "text" : "password";
}
/* ---------------- CLEAR ERRORS ---------------- */
function clearErrors() {
document.querySelectorAll(".error").forEach(err => {
err.style.display = "none";
});
}
/* ---------------- FORM SUBMIT ---------------- */
form.addEventListener("submit", function (e) {
e.preventDefault();
clearErrors();
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const password = document.getElementById("password").value.trim();
let isValid = true;
if (isSignup && name === "") {
document.getElementById("nameError").style.display = "block";
isValid = false;
}
if (!email.includes("@") || email === "") {
document.getElementById("emailError").style.display = "block";
isValid = false;
}
if (password.length < 6) {
document.getElementById("passwordError").style.display = "block";
isValid = false;
}
if (!isValid) return;
/* -------- SIGN UP LOGIC -------- */
if (isSignup) {
const user = { name, email, password };
localStorage.setItem("user", JSON.stringify(user));
successMsg.style.display = "block";
successMsg.innerText = "Signup successful 🎉 Please login now.";
toggleForm(); // Switch to login
return;
}
/* -------- LOGIN LOGIC -------- */
const savedUser = JSON.parse(localStorage.getItem("user"));
if (!savedUser) {
alert("No account found. Please sign up first.");
return;
}
if (email === savedUser.email && password === savedUser.password) {
successMsg.style.display = "block";
successMsg.innerText = `Welcome back, ${savedUser.name} ✅`;
form.reset();
} else {
alert("Invalid email or password ❌");
}
});
Related Projects
Day 2 : Multi-Step Form
A step-by-step form with progress tracking and input validation.
Concepts: DOM manipulation, form validation, progress tracking.
Day 3 : OTP Verification UI
Generates an OTP shown via alert and verifies it through a popup-based input UI.
Concepts: DOM manipulation, modal UI, random OTP generation, input handling.
Day 4 : Search Autocomplete Feature
Displays real-time search suggestions with keyboard navigation and highlighted matches.
Concepts: DOM manipulation, debounce, keyboard events, array filtering.