HTML Input Types

HTML Input Types: Collecting Data the Right Way

Forms are the user’s voice on your website — and input fields are how you hear it. HTML offers a wide range of <input> types to collect everything from simple text to dates and files. Choosing the right type enhances both usability and validation.

1. Text Input

This is the most basic input field, used to collect short single-line text like names, fruits, or cities.

<label for="fruit">Favorite Fruit:</label>
<input type="text" id="fruit" name="fruit" placeholder="Apple">
HTML - Text Input

2. Password

This field hides user input behind dots or asterisks — perfect for login forms.

<label for="password">Password:</label>
<input type="password" id="password" name="password">
HTML - Password Input

Though it hides the characters, remember — it's not encrypted. That happens on the backend.

3. Email

This input expects a properly formatted email address. Most browsers also trigger email-specific keyboards on mobile.

<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="hello@example.com">
HTML - Email Input

Try submitting the form with an invalid email, and you'll see the browser prevent it.

4. Number

Use this to accept numeric input only. You can also define minimum and maximum values.

<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" min="1" max="10">
HTML - Number Input
HTML - Number Input with Value

The up/down arrows help the user adjust the value easily.

5. Date

The date input brings up a calendar picker — a user-friendly way to select a date.

<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">
HTML - Date Input
HTML - Date Input Calender shown

6. File

Let users upload files from their device. Common for profile pictures or documents.

<label for="upload">Upload Image:</label>
<input type="file" id="upload" name="image">
HTML - File Input

Remember to set enctype="multipart/form-data" in your form when handling file uploads.

7. Checkbox

Checkboxes allow users to select multiple options from a group.

<p>Choose your fruits:</p>
<input type="checkbox" id="apple" name="fruit" value="apple">
<label for="apple">Apple</label>
<br>
<input type="checkbox" id="banana" name="fruit" value="banana">
<label for="banana">Banana</label>
HTML - Checkbox Input

8. Radio

Radio buttons let the user choose one — and only one — option from a group.

<p>Pick one:</p>
<input type="radio" id="cherry" name="vote" value="cherry">
<label for="cherry">Cherry</label>
<br>
<input type="radio" id="banana" name="vote" value="banana">
<label for="banana">Banana</label>
HTML - Radio Input

All radio inputs must share the same name to work together as a group.

9. Hidden

This input doesn’t show on the page, but it's useful for passing preset values during form submission.

<input type="hidden" name="source" value="signup-page">

It’s often used behind the scenes for tracking, context, or analytics.

10. Submit and Reset

<input type="submit" value="Submit">
<input type="reset" value="Clear">
HTML - Submit and Reset Input

submit triggers form submission, and reset clears all fields.

Summary of Input Types

TypeDescription
textSingle-line text input
passwordHidden input for passwords
emailValidates email format
numberNumeric input with range options
dateCalendar date picker
fileFile selection from device
checkboxMultiple selections allowed
radioSingle selection from a group
hiddenInvisible data passed with form
submit / resetTrigger or reset the form

Check your understanding 1

Which input type is best suited for capturing a student's name in an HTML form?
Choose one answer. You can try again.

Answer and explanation

<code>text</code>

For capturing names or general text, the type="text" input is ideal. It allows free-form alphanumeric input suited for fields like 'Student Name' or 'City'.

Check your understanding 2

The input type password masks the entered characters for security.
Choose one answer. You can try again.

Answer and explanation

True

Yes, <input type="password"> hides the actual characters typed, making it suitable for login or private data entry forms.

Check your understanding 3

Choose the option that lists all and only the correct statements.

  1. email
  2. number
  3. url
  4. text
Which of the following input types automatically perform basic validation in the browser?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 2 and 3

HTML5 input types like email, number, and url include built-in validation. text does not validate unless extra constraints (like pattern) are applied.

Check your understanding 4

Which input type is most suitable for capturing a student's marks in Mathematics out of 100?
Choose one answer. You can try again.

Answer and explanation

<code>number</code>

type="number" ensures that only numerical values are accepted. You can also set min and max attributes to constrain input to a valid range (e.g., 0–100).

Check your understanding 5

The input type email checks for the presence of '@' and '.' before submission.
Choose one answer. You can try again.

Answer and explanation

True

Yes, the email type includes basic format validation for email addresses, helping prevent malformed input at the client side.

Check your understanding 6

Choose the option that lists all and only the correct statements.

  1. <input type="text" name="student_name">
  2. <input type="email" name="parent_email">
  3. <input type="password" name="login_pin">
  4. <input type="file" name="profile_photo">
Which of the following input types can be used to collect data in a school admission form?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 2 and 3 and 4

All of these are valid and commonly used inputs in a school admission form — for student name, parent’s email, login credentials, and uploading documents or photos.

Best Practices

  • Use the right input type for better UX and native validation
  • Add name attributes to ensure fields are submitted properly
  • Use placeholder and label together for clarity and accessibility

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: HTML Labels and Placeholders →