WebecomIndia

Dark Mode Login Form with HTML and CSS

Dark Mode Login Form with HTML and CSS

In today’s web development landscape, a visually appealing and user-friendly login form is crucial. With the increasing popularity of dark mode, creating a dark mode login form can enhance user experience, reduce eye strain, and give your website a modern look. In this blog, we will guide you through the steps to create an attractive dark mode login form using HTML and CSS.

Why Dark Mode?

Dark mode has become a significant trend for several reasons:

  • Reduces Eye Strain: Dark mode is easier on the eyes, especially in low-light environments.
  • Energy Efficiency: It can save battery life on devices with OLED and AMOLED screens.
  • Modern Aesthetics: Dark themes often provide a sleek, modern, and professional look.

Setting Up the HTML Structure

The first step is to set up the basic HTML structure for our login form. Below is the HTML code for the form:

				
					<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Dark Mode Login Form</title>
  <style>
    /* CSS will go here */
  </style>
</head>
<body>
  <form class="form">
    <p id="heading">Login</p>
    <div class="field">
      <svg class="input-icon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
        <path d="M13.106 7.222c0-2.967-2.249-5.032-5.482-5.032-3.35 0-5.646 2.318-5.646 5.702 0 3.493 2.235 5.708 5.762 5.708.862 0 1.689-.123 2.304-.335v-.862c-.43.199-1.354.328-2.29.328-2.926 0-4.813-1.88-4.813-4.798 0-2.844 1.921-4.881 4.594-4.881 2.735 0 4.608 1.688 4.608 4.156 0 1.682-.554 2.769-1.416 2.769-.492 0-.772-.28-.772-.76V5.206H8.923v.834h-.11c-.266-.595-.881-.964-1.6-.964-1.4 0-2.378 1.162-2.378 2.823 0 1.737.957 2.906 2.379 2.906.8 0 1.415-.39 1.709-1.087h.11c.081.67.703 1.148 1.503 1.148 1.572 0 2.57-1.415 2.57-3.643zm-7.177.704c0-1.197.54-1.907 1.456-1.907.93 0 1.524.738 1.524 1.907S8.308 9.84 7.371 9.84c-.895 0-1.442-.725-1.442-1.914z"></path>
      </svg>
      <input autocomplete="off" placeholder="Username" class="input-field" type="text">
    </div>
    <div class="field">
      <svg class="input-icon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
        <path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2z"></path>
      </svg>
      <input placeholder="Password" class="input-field" type="password">
    </div>
    <div class="btn">
      <button class="button1">Login</button>
      <button class="button2">Sign Up</button>
    </div>
    <button class="button3">Forgot Password</button>
  </form>
</body>
</html>

				
			

Adding CSS for Styling

Next, we’ll add CSS to style our login form. The goal is to create a form that looks good in dark mode and is easy to use. Here’s the CSS code:

				
					body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000000;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2em;
  background-color: #171717;
  border-radius: 25px;
  transition: 0.4s ease-in-out;
  max-width: 300px;
}

.form:hover {
  transform: scale(1.05);
  border: 1px solid black;
}

#heading {
  text-align: center;
  margin-bottom: 1em;
  color: #fff;
  font-size: 1.5em;
}

.field {
  display: flex;
  align-items: center;
  gap: 0.5em;
  border-radius: 25px;
  padding: 0.6em;
  background-color: #171717;
  box-shadow: inset 2px 5px 10px #050505;
}

.input-icon {
  height: 1.3em;
  width: 1.3em;
  fill: #fff;
}

.input-field {
  background: none;
  border: none;
  outline: none;
  width: 100%;
  color: #d3d3d3;
}

.btn {
  display: flex;
  justify-content: center;
  gap: 1em;
  margin-top: 1.5em;
}

.button1, .button2, .button3 {
  padding: 0.5em 1em;
  border-radius: 5px;
  border: none;
  outline: none;
  transition: 0.4s ease-in-out;
  background-color: #252525;
  color: #fff;
}

.button1:hover, .button2:hover, .button3:hover {
  background-color: black;
  color: #fff;
}

.button3 {
  margin-top: 1em;
}
    
				
			

Explanation of the CSS

  • Body Styling: We set the body to cover the full viewport height and center the form both vertically and horizontally. The background color is set to black to create a dark mode effect.
  • Form Styling: The form has a dark background color, rounded corners, and a slight scaling effect on hover for a modern look. Padding and a maximum width are set for better alignment and spacing.
  • Heading Styling: The heading is centered, with a white font color and a slightly larger font size for prominence.
  • Field Styling: The fields are styled to have rounded corners, padding, and a dark background with an inset shadow for a sunken effect. Icons are white to stand out against the dark background.
  • Button Styling: Buttons are styled with padding, rounded corners, and transition effects to change background color on hover, enhancing interactivity and visual feedback.

Making the Form SEO-Friendly

To ensure our login form is SEO-friendly, we should use semantic HTML, add meta tags, and consider accessibility. Here are some tips:

Meta Tags for SEO

Add the following meta tags to the <head> section of your HTML:

				
					<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="A sleek and modern dark mode login form designed with HTML and CSS.">
  <meta name="keywords" content="login form, dark mode, HTML, CSS, web design, user interface">
  <meta name="author" content="Your Name">
  <title>Dark Mode Login Form</title>
</head>

				
			

Accessibility Considerations

Ensuring accessibility means making your login form usable by as many people as possible, including those with disabilities. Here are some ways to enhance accessibility:

  • Use ARIA (Accessible Rich Internet Applications) attributes: These attributes help assistive technologies understand and interact with your form.
  • Provide clear labels: Use the label element to associate labels with form controls.
  • Keyboard Navigation: Ensure that all interactive elements are accessible via keyboard.
				
					<label for="username">Username</label>
<input id="username" name="username" type="text" placeholder="Username" aria-label="Username">

<label for="password">Password</label>
<input id="password" name="password" type="password" placeholder="Password" aria-label="Password">

				
			
Scroll to Top