HTML Input Types
Learn how to create interactive forms with different input types in HTML.
What is an HTML Input?
HTML Input elements allow users to enter data in forms. They are the building blocks of forms and can accept text, numbers, dates, selections, and more.
- Collect user information like name, email, password
- Allow choices via checkboxes, radio buttons, or dropdowns
- Enable user interaction in websites and applications
Real-Life Example: Like a registration form in apps, HTML inputs help users provide necessary information to websites.
Common HTML Input Types
text– Single-line text inputpassword– Hidden text for passwordsemail– Email address input with validationnumber– Numeric input with min/maxdate– Date selectioncheckbox– Multiple options selectionradio– Single option selection from a groupsubmit– Submit form datareset– Reset form fields
HTML Input Examples
Example 1: Text, Email, and Password Inputs
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<input type="submit" value="Register">
</form>
Example 2: Number, Date, and Checkbox Inputs
<form>
<label for="age">Age:</label>
<input type="number" id="age" name="age" min="1" max="100">
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob">
<label>
<input type="checkbox" name="newsletter"> Subscribe to newsletter
</label>
<input type="submit" value="Submit">
</form>
Example 3: Radio Buttons
<form>
<p>Gender:</p>
<label>
<input type="radio" name="gender" value="male"> Male
</label>
<label>
<input type="radio" name="gender" value="female"> Female
</label>
<input type="submit" value="Submit">
</form>
Best Practices for Input Types
- Always use
labelfor accessibility - Use proper
typeto leverage browser validation - Set
requiredattribute for mandatory fields - Provide placeholder text for better UX
- Use min, max, and step for number inputs
- Group radio buttons and checkboxes with
fieldsetandlegend
Pro Tip: Correct input types improve user experience, form validation, and accessibility.