What is an HTML Form?
An HTML form is used to collect user input.
Examples:
- Login form
- Registration form
- Contact form
Basic Form Structure
<form>
<!-- form elements -->
</form>Form Tag Attributes
1. action
Tells where form data is sent
<form action="submit.php">2. method
Tells how data is sent
<form method="post">| Method | Use |
| get | Data visible in URL |
| post | Data hidden |
3. target
<form target="_blank">Form Elements
1. <input> Tag
Used to take user input.
Common Input Types & Attributes
Text Input
<input type="text" name="username" placeholder="Enter name">Password Input
<input type="password" name="password">Email Input
<input type="email" name="email">Number Input
<input type="number" min="1" max="100">Radio Button
<input type="radio" name="gender"> Male
<input type="radio" name="gender"> FemaleCheckbox
<input type="checkbox"> HTML
<input type="checkbox"> CSSImportant <input> Attributes
| Attribute | Use |
| type | Input type |
| name | Field name |
| value | Default value |
| placeholder | Hint text |
| required | Mandatory |
| readonly | Cannot edit |
| disabled | Disabled field |
2. <label> Tag
<label>Name:</label>
<input type="text">3. <textarea>
<textarea rows="4" cols="30"></textarea>4. <select> & <option>
<select>
<option>HTML</option>
<option>CSS</option>
</select>5. <button>
<button type="submit">Submit</button>Complete Example Form
<form action="save.php" method="post">
<label>Name:</label>
<input type="text" required>
<label>Email:</label>
<input type="email">
<button>Submit</button>
</form>Important Notes
- Always use name attribute
- Use label for accessibility
- Use post for sensitive data
