Source Code

[Download]Responsive Login Page Using HTML, CSS, and JavaScript

Ravindra Kumar

A login page is a fundamental part of any website that requires authentication. A well-designed login page ensures a seamless user experience and enhances security. In this blog post, we’ll guide you through designing a stylish and fully responsive login page using HTML, CSS, and JavaScript.

Step 1: Structuring the HTML

The first step in building a login page is structuring the HTML. We’ll create a container for the login form and add input fields for the username and password. Additionally, we’ll include a ‘Forgot Password’ link and a ‘Remember Me’ checkbox.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Page</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="login-container">
        <h2>Login</h2>
        <form id="loginForm">
            <div class="input-group">
                <label for="username">Username</label>
                <input type="text" id="username" placeholder="Enter your username">
            </div>
            <div class="input-group">
                <label for="password">Password</label>
                <input type="password" id="password" placeholder="Enter your password">
            </div>
            <div class="remember-me">
                <div>
                    <input type="checkbox" id="rememberMe">
                    <label for="rememberMe">Remember Me</label>
                </div>
                <a href="#">Forgot Password?</a>
            </div>
            <button type="button" onclick="validateLogin()">Login</button>
        </form>
    </div>
    <script src="script.js"></script>
</body>
</html>

Step 2: Styling with CSS

To make the login page visually appealing and responsive, we’ll use CSS. The form will be centered, have a modern look, and be fully responsive on all devices.

body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f4f4f4;
    margin: 0;
}

.login-container {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
    width: 350px;
    text-align: center;
}

.input-group {
    margin-bottom: 15px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.input-group input {
    width: calc(100% - 20px);
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 16px;
    display: block;
    margin: 0 auto;
}

.remember-me {
    display: flex;
    align-items: center;
    font-size: 14px;
    margin-bottom: 15px;
    justify-content: space-between;
}

.remember-me a {
    text-decoration: none;
    color: #007bff;
    font-size: 14px;
}

.remember-me a:hover {
    text-decoration: underline;
}

button {
    width: 100%;
    padding: 12px;
    border: none;
    background-color: #28a745;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}

button:hover {
    background-color: #218838;
}

/* Responsive Design */
@media (max-width: 480px) {
    .login-container {
        width: 90%; /* Adjust width for smaller screens */
        padding: 15px;
    }

    .input-group input {
        width: 100%; /* Full width input fields */
    }
}

Step 3: Adding JavaScript for Form Validation

A simple JavaScript function is added to validate user input before submitting the form.

function validateLogin() {
    let username = document.getElementById("username").value;
    let password = document.getElementById("password").value;
    if (username === "" || password === "") {
        alert("Please enter both username and password.");
    } else {
        alert("Login successful! (Demo purpose only)");
    }
}

Making the Form Fully Responsive

To ensure the login page works well on all screen sizes, we included a media query in the CSS file. This ensures that on smaller devices like mobile phones, the form adapts by adjusting its width and padding.

Why These Changes Improve Responsiveness?

✔ Ensures proper spacing and readability✔ Makes input fields adapt to small screens✔ Keeps the form centered and visually appealing

Download Login Page Source Code

PHP Login Dashboard Template with Bootstrap Free Download

Ravindra Kumar

Ravindra is a passionate full stack developer and dedicated blogger with a flair for crafting user-friendly web applications and insightful articles. With expertise spanning front-end and back-end technologies, Ravindra brings ideas to life through innovative coding solutions.

Suggested Reading

Free Download Books, Stationery & Art Supplies Website Template – HTML, CSS, JS

Create an engaging online presence for your bookstore, stationery shop, craft store, or art supplies brand with our beautifully designed Books, Stationery & Art Supplies Website Template. This template combines clean layouts, warm aesthetics, and user-friendly navigation to help you showcase your products in the most appealing way. Whether you’re selling books, journals, office supplies, […]

Free Download Electronics & Gadgets Website Template Using HTML, CSS, JS

Power up your online presence with our Electronics & Gadgets Website Template, designed for tech stores, gadget retailers, electronics showrooms, and eCommerce startups. This high-performance template combines sleek design, advanced functionality, and cutting-edge style — perfect for showcasing the latest devices, smart accessories, and innovative tech products. Built with precision and modern web standards, this […]

Download Free Beauty, Health & Personal Care Website Template Using HTML, CSS, Js

Create a stunning online presence with our Beauty, Health & Personal Care Website Template — designed for beauty brands, salons, skincare stores, and wellness professionals. This elegant and responsive template highlights your products and services with smooth layouts, soothing colors, and a clean user experience. Whether you run a spa, salon, cosmetic store, or fitness […]

Download Free Food & Grocery Website Template using HTML, CSS, JS

Create a Modern and Responsive Online Store for Food, Grocery, or Organic Products This Food & Grocery Website Template is ideal for supermarkets, organic food brands, local grocery shops, restaurants, or farm-to-table businesses looking to go digital.It’s fast, responsive, and beautifully structured to help your customers shop with ease. 🥗 Template Features Fully responsive and […]

Download Free Home & Lifestyle Website Template Using HTML, CSS, JS

Build a Modern, Stylish Website for Your Home & Living Brand This Home & Lifestyle Website Template is crafted for brands, decor stores, and lifestyle bloggers who want a clean, elegant online presence.Showcase your products, home styling ideas, or interior designs with a responsive, easy-to-edit layout that speaks sophistication and warmth. ✨ Template Features Fully […]

Download Free Jewelry & Luxury Store Website Template Using HTML, CSS, JS

Showcase Your Brand with Elegance and Sophistication This Jewelry & Luxury Store Website Template is designed to reflect the beauty and exclusivity of your brand. Whether you sell diamonds, gold jewelry, watches, or designer accessories, this template helps you create a luxurious digital storefront with ease. Key Features Elegant, high-end design layout Fully responsive across […]