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

Professional Website Templates Free Download HTML

About This Resource Explore a collection of professional website templates available for free download in HTML format. These templates are designed to help you build stunning and responsive websites quickly and efficiently, without any cost. Key Features Clean and modern design suitable for various industries Fully responsive templates optimized for all devices Easy to customize […]

Free Play School Website Templates for Easy and Engaging Online Presence

About This Theme / Template / Resource Our Play School Website Templates are designed to create a vibrant and engaging online presence for educational institutions focused on early childhood learning. These templates are perfect for preschools, daycare centers, and play schools that want a professional, child-friendly website without the complexity of custom coding. Key Features […]

Download Free Parallax Website HTML Template

About This Theme / Template / Resource This free parallax website HTML template provides a modern and visually appealing design that uses smooth parallax scrolling effects to enhance user experience. It is perfect for creating impactful, professional websites that stand out with dynamic backgrounds and layered content effects. Key Features Fully responsive and mobile-friendly layout […]

Free Download: Online Exam Website Templates with HTML and CSS

About This Resource Discover the best online exam website templates designed with clean HTML and CSS. These free templates provide a professional and user-friendly framework for creating robust online examination platforms quickly and efficiently. Key Features Responsive design compatible with all devices Clean and well-organized HTML and CSS code Multiple page layouts for exam listings, […]

Free Multi Page Website Templates with HTML and CSS

About This Resource Discover a collection of free multi page website templates crafted with clean HTML and CSS. These templates are designed to help you build professional, responsive websites with multiple pages easily and efficiently. Key Features Fully responsive design to fit all device screens Multiple pages including Home, About, Services, Contact, and more Clean […]

Free HTML Personal Website Templates for Download

About This Resource Explore a collection of free HTML personal website templates designed for individuals who want to create a professional online presence easily. These templates are perfect for showcasing your portfolio, resume, blog, or personal brand with clean, modern designs. Key Features Responsive design for all devices Clean and modern layout Easy to customize […]