Login Page In Html With Css Code

As a website developer, a crucial element of any online platform is a login page. This page provides a secure way for users to access their accounts and personalized features or services. In this article, I will guide you through the steps of building a login page with HTML and CSS code, while also incorporating my own insights and remarks.

HTML Structure

To begin, let’s outline the basic structure of our login page. We’ll be using HTML to define the elements and CSS to style them. Start by creating a new HTML file and adding the following code:


<!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="container">
      <h2>Login to MyWebsite</h2>
      <form>
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>
        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required>
        <input type="submit" value="Login">
      </form>
    </div>
  </body>
</html>

Let’s break down the code above. Starting with the doctype declaration, we specify that our document follows the HTML5 standard. In the head section, we set the character encoding and define the viewport for responsive design. We also include a link to an external CSS file called “styles.css” to keep our styles separate from the HTML code.

The body section contains a container div that wraps all the elements of our login page. Inside the container, we have an h2 heading that displays the title of our login page. Below the heading, we have a form element that contains two input fields for the username and password. Each input element is labeled appropriately using the label element. Finally, we have a submit button that allows the user to submit their login information.

CSS Styling

Now that we have the basic HTML structure in place, let’s add some CSS styles to make our login page visually appealing. Create a new file called “styles.css” and add the following code:


.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 100px;
  width: 300px;
  background-color: #f2f2f2;
  padding: 20px;
  border-radius: 5px;
  box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
}

h2 {
  text-align: center;
  margin-bottom: 20px;
}

form {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
}

label {
  margin-bottom: 5px;
}

input {
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

input[type="submit"] {
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 5px;
  padding: 10px;
  cursor: pointer;
}

The CSS code above targets the various elements of our login page and applies styles to them. First, we style the container div by making it a flex container with centered alignment. We also give it a specific width, background color, padding, border radius, and box shadow to create a clean and modern look.

The h2 heading is centered and has a margin-bottom to create some spacing between the heading and the form. The form is displayed as a flex container with a column direction, allowing the input fields to stack vertically. Each label has a margin-bottom for spacing, and the input fields have some padding and a border to make them stand out. Finally, the submit button has a distinct background color and border radius to make it visually appealing.

Conclusion

And there you have it! By following this step-by-step guide, you should now have a functional and visually appealing login page created using HTML and CSS code. Remember, this is just a starting point, and you can always customize the design further to match your project’s requirements or personal preferences. Happy coding!