HTML LOGIN FORM CODE: A COMPREHENSIVE GUIDE
Creating a login form in HTML is essential for many web applications. It allows users to authenticate themselves before accessing certain features or content.
Here’s a basic structure:
```html
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=
- 0">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="login-container">
<h2>ورود به حساب کاربری</h2>
<form action="login.php" method="POST">
<label for="username">نام کاربری:</label>
<input type="text" id="username" name="username" required>
<label for="password">کلمه عبور:</label>
<input type="password" id="password" name="password" required>
<button type="submit">ورود</button>
</form>
</div>
</body>
</html>
```
LET'S BREAK IT DOWN:
- DOCTYPE Declaration:
- HTML Tag:
- Head Section:
- Title:
- CSS Link:
- Body Section:
- Form Element:
- Input Fields:
- `required` ensures users fill these fields.
- Submit Button:
STYLING AND FUNCTIONALITY:
To make your form visually appealing, consider adding CSS. For instance:
```css
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.login-container {
max-width: 400px;
margin: 100px auto;
padding: 20px;
background: white;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0,0,0,
- 1);
h2 {
text-align: center;
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
```
In conclusion, with these elements combined, your login form will not only function well but also provide a pleasant user experience. This basic structure can be enhanced further with JavaScript for validation or additional features like "Remember Me" checkboxes or social media login options.