Forgot Password Page Using HTML, CSS, and Js
Published on January 2, 2025
A "Forgot Password" form helps users recover their accounts by resetting their passwords. This post will demonstrate how to create a simple and effective forgot password form using HTML, CSS, and JavaScript.
HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forgot Password Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="form-container">
<h2>Forgot Password</h2>
<form id="forgotPasswordForm">
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email" placeholder="Your registered email" required>
<button type="submit">Reset Password</button>
</form>
<div id="responseMessage"></div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS Code
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.form-container {
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 350px;
text-align: center;
}
h2 {
color: #333;
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
color: #555;
}
input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 14px;
}
button {
background: #007BFF;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
width: 100%;
font-size: 16px;
transition: background 0.3s ease;
}
button:hover {
background: #0056b3;
}
JavaScript Code
document.getElementById("forgotPasswordForm").addEventListener("submit", function (e) {
e.preventDefault();
const email = document.getElementById("email").value;
if (email) {
document.getElementById("responseMessage").textContent = "Password reset link sent to your email.";
document.getElementById("responseMessage").style.color = "green";
} else {
document.getElementById("responseMessage").textContent = "Please enter a valid email.";
document.getElementById("responseMessage").style.color = "red";
}
});
How It Works
1. **HTML**: The form includes an input field for the user's email address and a button to submit the request. 2. **CSS**: Styling ensures the form is visually appealing and centered on the page. 3. **JavaScript**: On form submission, the script checks if an email is entered and displays a success or error message accordingly.

Join the conversation