Lesson 5 - HTML Forms for Beginners: How to Collect User Input Like a Pro
Want to create contact forms, surveys, or login pages? Learn how to build and structure HTML forms with input fields, labels, buttons, and more in this step-by-step guide for beginners.
WEB DEVELOPMENT
Leonardo Gomes Guidolin
4/20/20252 min read
👋 Introduction
If you’ve followed the last lessons, you now know how to build static content using HTML. But what if you want to let users interact with your site—like sending a message, filling out a survey, or logging in?
That’s where HTML forms come in. Forms are essential for collecting data from users and are used everywhere—from search bars to payment gateways.
🧱 Basic Form Structure
Here’s what a minimal form looks like in HTML:
<form action="/submit" method="POST">
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<input type="submit" value="Submit">
</form>
Explanation:
<form>: Wraps all form elements.
action: Defines where the form sends its data.
method: GET (for reading data) or POST (for sending data).
<label>: Improves usability and accessibility.
<input>: The actual field where users type.
🧰 Common Form Elements and How to Use Them
🔤 Text Input
<input type="text" name="fullname" placeholder="Enter your full name">
📧 Email Input
<input type="email" name="email" required>
🔒 Password Input
<input type="password" name="password">
☑️ Checkbox
<label><input type="checkbox" name="subscribe"> Subscribe to newsletter</label>
🔘 Radio Button
<label><input type="radio" name="gender" value="male"> Male</label>
<label><input type="radio" name="gender" value="female"> Female</label>
🔽 Select Dropdown
<select name="country">
<option value="us">United States</option>
<option value="br">Brazil</option>
</select>
📝 Textarea (Multiline Text)
<textarea name="message" rows="4" cols="40" placeholder="Type your message..."></textarea>
▶️ Submit Button
<input type="submit" value="Send">
You can also use:
<button type="submit">Send Message</button>
🔐 Understanding Form Attributes
action - URL to send the form data
method - HTTP method: GET or POST
name - Identifier for the form field (used on the backend)
placeholder - Guide text inside the input
required - Makes the field mandatory
disabled - Makes the field uneditable
value - Default value for the input
🧪 Example: Contact Form
<form action="/contact" method="POST">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name" required><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message" rows="4"></textarea><br>
<button type="submit">Send</button>
</form>
💡 Best Practices
Always include <label> elements linked to inputs using for and id.
Use required to ensure essential data is collected.
Validate on both the client side (HTML/JS) and server side (Python, PHP, etc).
Keep forms accessible (use semantic elements and consider screen readers).
🚀 Bonus: Styling Your Form (Sneak Peek)
Want to make your form look professional? Here's a teaser of what we'll cover in the next lesson:
input, textarea {
width: 100%;
padding: 8px;
margin-top: 6px;
margin-bottom: 12px;
border: 1px solid #ccc;
border-radius: 4px;
}
🔚 Conclusion
Forms are the gateway between your users and your website’s functionality. Whether you're building a sign-up page or collecting feedback, mastering forms is a key skill for any web developer.
In the next lesson, we’ll take your forms from functional to beautiful using CSS styling techniques!