📝 HTML Form Tutorial
If you want to collect user information on your website—like names, emails, or messages—you need HTML forms.
Forms are one of the most important parts of web development. They are used in:
- Login pages 🔐
- Contact forms 📩
- Registration systems 🧾
- Surveys and feedback ⭐
In this complete guide, you’ll learn everything about HTML forms with simple examples.
🌐 What is an HTML Form?
An HTML form is used to collect user input and send it to a server.
Basic Structure:
<form>
<!-- form elements go here -->
</form>
<form>
<!-- form elements go here -->
</form>🔹 1. Input Fields
The <input> tag is the most used form element.
Example:
<input type="text" placeholder="Enter your name">
<input type="text" placeholder="Enter your name">🔹 2. Types of Input Fields
Text Input
<input type="text" placeholder="Your Name">
<input type="text" placeholder="Your Name">Email Input
<input type="email" placeholder="Your Email">
<input type="email" placeholder="Your Email">Password Input
<input type="password" placeholder="Password">
<input type="password" placeholder="Password">Number Input
<input type="number" placeholder="Your Age">
<input type="number" placeholder="Your Age">Date Input
<input type="date">
<input type="date">🔹 3. Labels (Important for Accessibility)
Labels describe inputs.
<label for="name">Name:</label>
<input type="text" id="name">🔹 4. Buttons
<button type="submit">Submit</button>
<button type="submit">Submit</button>🔹 5. Textarea (Multi-line Input)
<textarea placeholder="Your message"></textarea>
<textarea placeholder="Your message"></textarea>🔹 6. Select Dropdown
<select>
<option>Male</option>
<option>Female</option>
</select>
<select>
<option>Male</option>
<option>Female</option>
</select>🔹 7. Radio Buttons
<input type="radio" name="gender"> Male
<input type="radio" name="gender"> Female
<input type="radio" name="gender"> Male
<input type="radio" name="gender"> Female🔹 8. Checkboxes
<input type="checkbox"> I agree to terms
<input type="checkbox"> I agree to terms🔹 9. Form Attributes
<form action=\"submit.php\" method=\"POST\">
- action → where data is sent
- method → GET or POST
<form action=\"submit.php\" method=\"POST\">🔹 10. Required Fields & Validation
<input type="email" required>
<input type="email" required>👉 Prevents empty submission.
🎨 Styled Form Example (HTML + CSS)
HTML
<form class="form">
<h2>Contact Us</h2>
<input type="text" placeholder="Your Name" required>
<input type="email" placeholder="Your Email" required>
<textarea placeholder="Your Message"></textarea>
<button type="submit">Send</button>
</form>
<form class="form">
<h2>Contact Us</h2>
<input type="text" placeholder="Your Name" required>
<input type="email" placeholder="Your Email" required>
<textarea placeholder="Your Message"></textarea>
<button type="submit">Send</button>
</form>CSS
.form {
width: 300px;
padding: 20px;
background: linear-gradient(to right, #4facfe, #00f2fe);
border-radius: 10px;
}
.form input,
.form textarea {
width: 100%;
margin: 10px 0;
padding: 10px;
border: none;
border-radius: 5px;
}
.form button {
width: 100%;
padding: 10px;
background: #0000ff;
color: white;
border: none;
border-radius: 5px;
}
.form {
width: 300px;
padding: 20px;
background: linear-gradient(to right, #4facfe, #00f2fe);
border-radius: 10px;
}
.form input,
.form textarea {
width: 100%;
margin: 10px 0;
padding: 10px;
border: none;
border-radius: 5px;
}
.form button {
width: 100%;
padding: 10px;
background: #0000ff;
color: white;
border: none;
border-radius: 5px;
}📱 Making Forms Responsive
@media (max-width: 600px) {
.form {
width: 100%;
}
}
@media (max-width: 600px) {
.form {
width: 100%;
}
}🚀 Best Practices
- Always use labels
- Keep forms simple
- Use proper input types
- Add validation
- Make it mobile-friendly
🎯 Common Mistakes
❌ No labels
❌ Too many fields
❌ No validation
❌ Poor design
🧠 Final Thoughts
HTML forms are essential for any interactive website. Once you understand how they work, you can build login systems, contact pages, and much more.
Start simple, practice often, and improve your design with CSS.
Basic Form
<form> <input type="text" placeholder="Your Name"> </form>
Input Types
<input type="email"> <input type="password"> <input type="number">
Textarea
<textarea></textarea>
Button
<button>Submit</button>

Comments
Post a Comment