Login form with background image using HTML & CSS

Here's an example of a login form with a background image using HTML and CSS:

html
<!DOCTYPE html>
<html>
    <head>
        <title>Login Form with Background Image</title>
        <style>
            * {
                box-sizing: border-box;
            }

            body {
                font-family: Arial, sans-serif;
                margin: 0;
            }

            .container {
                position: relative;
                height: 100vh;
                background-image: url('background-image.jpg');
                background-size: cover;
                background-position: center;
                display: flex;
                align-items: center;
                justify-content: center;
            }

            .login-form {
                max-width: 400px;
                padding: 20px;
                background-color: rgba(255, 255, 255, 0.8);
                border-radius: 5px;
            }

            h1 {
                text-align: center;
            }

            .form-group {
                margin-bottom: 20px;
            }

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

            input[type="text"],
            input[type="password"] {
                width: 100%;
                padding: 10px;
                border: 1px solid #ccc;
                border-radius: 5px;
            }

            .btn {
                width: 100%;
                padding: 10px;
                background-color: #4CAF50;
                color: #fff;
                border: none;
                border-radius: 5px;
                cursor: pointer;
            }

            .btn:hover {
                opacity: 0.8;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="login-form">
                <h1>Login Form</h1>
                <form>
                    <div class="form-group">
                        <label for="username">Username:</label>
                        <input type="text" id="username" name="username" placeholder="Enter your username">
                    </div>
                    <div class="form-group">
                        <label for="password">Password:</label>
                        <input type="password" id="password" name="password" placeholder="Enter your password">
                    </div>
                    <div class="form-group">
                        <input type="submit" class="btn" value="Login">
                    </div>
                </form>
            </div>
        </div>
    </body>
</html>

In this example, the login form is contained within a container div, which is set to a height of 100vh (100% of the viewport height). The background image is applied using the `background-image` property, with the image file specified in the `url()` function. You can replace `'background-image.jpg'` with the actual path to your background image.

The login form itself is styled with a semi-transparent background color using `rgba()` to allow the background image to show through. The form elements are centered within the container using flexbox properties (`display: flex; align-items: center; justify-content: center;`). The form input fields, labels, and buttons are styled with appropriate padding, borders, and colors.


Output:

img




About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext