This code creates a stylish login form with a background image using HTML and CSS. The form includes input fields for a username and password, a “Keep me Signed in” checkbox, and a “Sign In” button. The background image dynamically changes, providing an aesthetic appeal. The form design is enhanced with a modern color scheme and font. This code helps create an engaging and visually appealing login interface for websites or applications.
How to Create Login Form With Background Image In HTML CSS
1. Ensure you have the Montserrat font by adding the following link to the <head>
section of your HTML file.
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
2. Create the basic HTML structure for the login form. Include input fields for username and password, a “Keep me Signed in” checkbox, and a “Sign In” button. Don’t forget to add a link for password recovery.
<div class="login"> <h2 class="active"> sign in </h2> <h2 class="nonactive"> sign up </h2> <form> <input type="text" class="text" name="username"> <span>username</span> <br> <br> <input type="password" class="text" name="password"> <span>password</span> <br> <input type="checkbox" id="checkbox-1-1" class="custom-checkbox" /> <label for="checkbox-1-1">Keep me Signed in</label> <button class="signin"> Sign In </button> <hr> <a href="#">Forgot Password?</a> </form> </div>
3. Copy and paste the provided CSS code into your stylesheet. This code styles the login form, sets the background image dynamically, and adds modern aesthetics to the design.
body, .signin { background-color: #d3d3d3; font-family: 'Montserrat', sans-serif; color: #fff; font-size: 14px; letter-spacing: 1px; } .cd__main{ min-height: 720px; position: relative; } .login { position: relative; height: 560px; width: 405px; margin: auto; padding: 60px 60px; background: url(https://source.unsplash.com/1280x720/?nature) no-repeat center center #505050; background-size: cover; box-shadow: 0px 30px 60px -5px #000; } form { padding-top: 80px; } .active { border-bottom: 2px solid #1161ed; } .nonactive { color: rgba(255, 255, 255, 0.2); } h2 { padding-left: 12px; font-size: 22px; text-transform: uppercase; padding-bottom: 5px; letter-spacing: 2px; display: inline-block; font-weight: 100; } h2:first-child { padding-left: 0px; } span { text-transform: uppercase; font-size: 12px; opacity: 0.4; display: inline-block; position: relative; top: -65px; transition: all 0.5s ease-in-out; } .text { border: none; width: 89%; padding: 10px 20px; display: block; height: 15px; border-radius: 20px; background: rgba(255, 255, 255, 0.1); border: 2px solid rgba(255, 255, 255, 0); overflow: hidden; margin-top: 15px; transition: all 0.5s ease-in-out; } .text:focus { outline: 0; border: 2px solid rgba(255, 255, 255, 0.5); border-radius: 20px; background: rgba(0, 0, 0, 0); } .text:focus + span { opacity: 0.6; } input[type="text"], input[type="password"] { font-family: 'Montserrat', sans-serif; color: #fff; } input { display: inline-block; padding-top: 20px; font-size: 14px; } h2, span, .custom-checkbox { margin-left: 20px; } .custom-checkbox { -webkit-appearance: none; background-color: rgba(255, 255, 255, 0.1); padding: 8px; border-radius: 2px; display: inline-block; position: relative; top: 6px; } .custom-checkbox:checked { background-color: rgba(17, 97, 237, 1); } .custom-checkbox:checked:after { content: '\2714'; font-size: 10px; position: absolute; top: 1px; left: 4px; color: #fff; } .custom-checkbox:focus { outline: none; } label { display: inline-block; padding-top: 10px; padding-left: 5px; } .signin { background-color: #1161ed; color: #FFF; width: 100%; padding: 10px 20px; display: block; height: 39px; border-radius: 20px; margin-top: 30px; transition: all 0.5s ease-in-out; border: none; text-transform: uppercase; } .signin:hover { background: #4082f5; box-shadow: 0px 4px 35px -5px #4082f5; cursor: pointer; } .signin:focus { outline: none; } hr { border: 1px solid rgba(255, 255, 255, 0.1); top: 85px; position: relative; } .login a { text-align: center; display: block; top: 120px; position: relative; text-decoration: none; color: rgba(255, 255, 255, 0.2); }
Replace the placeholder background image URL in the CSS code with the desired image link to personalize your login form’s appearance.
That’s all! hopefully, you have successfully created a Login Form With a Background Image. If you have any questions or suggestions, feel free to comment below.
Similar Code Snippets:
I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences.
I truly enjoy what I’m doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.