Creating a login form using HTML and CSS

0
11كيلو بايت

Creating a login form using HTML and CSS is a fundamental skill in web development. Here's a step-by-step guide to building a simple and responsive login form:

1. HTML Structure

Begin by setting up the basic HTML structure for the login form. This includes a container for the form elements such as the username and password fields, and a submit button.

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login Form</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="login-container"> <h2>Login</h2> <form action="/login" method="post"> <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> <button type="submit">Login</button> </form> </div> </body> </html>

Explanation:

  • The <form> element wraps the input fields and the submit button.
  • Each <label> is associated with an <input> field, enhancing accessibility.
  • The required attribute ensures that users cannot submit the form without filling in these fields.

2. CSS Styling

Next, style the form to make it visually appealing and responsive.

css
 
/* styles.css */ body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; font-family: Arial, sans-serif; background-color: #f2f2f2; } .login-container { width: 100%; max-width: 400px; padding: 20px; background-color: #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 8px; } h2 { text-align: center; margin-bottom: 20px; } label { display: block; margin-bottom: 5px; font-weight: bold; } input[type="text"], input[type="password"] { width: 100%; padding: 10px; margin-bottom: 15px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button { width: 100%; padding: 10px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; } button:hover { background-color: #45a049; }

Explanation:

  • The body is styled to center the login form both vertically and horizontally.
  • The .login-container class styles the form container with a fixed width, padding, background color, shadow, and rounded corners.
  • Input fields and the button are styled for better user experience, with padding, borders, and hover effects.

3. Responsive Design

To ensure the form is responsive on various screen sizes, the .login-container is set to a maximum width and uses percentage-based widths for its elements. This allows the form to resize appropriately on different devices.

Love
1
البحث
الأقسام
إقرأ المزيد
Technology
The Ten Commandments of Computer Ethics
The Ten Commandments of Computer Ethics were created by the Computer Ethics Institute to guide...
بواسطة ALAGAI AUGUSTEN 2024-07-16 17:02:40 0 11كيلو بايت
Chemistry
UMTA UACE UMTA CHEMISTRY PAPER 1 2024 MOCKS
UMTA UACE CHEMISTRY PAPER 1 2024 MOCKS
بواسطة Landus Mumbere Expedito 2024-08-01 16:10:54 0 11كيلو بايت
Physics
COLLECTION OF PHYSICS SCENARIOS
COLLECTION OF PHYSICS SCENARIOS
بواسطة Landus Mumbere Expedito 2024-08-13 19:19:44 0 12كيلو بايت
Technology
Web Design Tools and Technologies
Web Design Tools and Technologies Web design has evolved dramatically over the past few decades,...
بواسطة ALAGAI AUGUSTEN 2024-07-26 17:47:49 0 21كيلو بايت
التعليم
S4 CHEMISTRY
https://acrobat.adobe.com/id/urn:aaid:sc:EU:c0424112-e1de-4038-84a6-6743ec084d39
بواسطة Landus Mumbere Expedito 2024-07-24 19:24:46 0 9كيلو بايت
Tebtalks https://forum.tebtalks.com