HTML Forms Tutorial
HTML Forms Tutorial
</form>
Attributes of <form>
<input type="text">
<input type="email">
<input type="number">
<input type="password">
<input type="date">
<input type="file">
<input type="submit">
Text Field
<label for="name">Name:</label>
<label for="pwd">Password:</label>
<label>Email:</label>
<label>Age:</label>
<p>Gender:</p>
<p>Hobbies:</p>
<label>Country:</label>
<select name="country">
<option value="Kenya">Kenya</option>
<option value="Uganda">Uganda</option>
</select>
Textarea
<label for="msg">Message:</label><br>
<select name="level">
<option>Beginner</option>
<option>Intermediate</option>
</select><br>
<textarea name="message"></textarea><br>
<input type="submit">
</form>
Styling Forms (CSS)
padding: 10px;
margin: 10px;
width: 100%;
}
Form Best Practices
- Full Name
- Age
- Gender (radio)
- Country (dropdown)
- Submit button
EXERCISE 2 - Registration Form
- Full Name
- Phone Number
- Date of Birth
- Gender (radio)
- Subjects (checkboxes)
- Comments (textarea)
- Name
- Phone
- CV Upload
- Agreement Checkbox
- Submit button
Bonus: JavaScript Form Validation
<script>
function validateForm() {
if (name == "") {
alert("Name is required");
return false;
</script>
<input type="submit">
</form>
Wrap-Up & Resources
- w3schools.com/html/html_forms.asp
Questions or Help?
Your Name