TetSharing
HTML tutorial · 12 chapters
  1. Get started
  2. Elements and attributes
  3. Headings and paragraphs
  4. Text formatting
  5. Links
  6. Images
  7. Lists
  8. Tables
  9. Forms
  10. Input types and controls
  11. Semantic layout
  12. Head and metadata

Final HTML quiz

Chapter 10 of 12 · By Ethan Cole · Updated November 21, 2026

HTML Input Types: text, number, date, radio and select

The type attribute turns one <input> element into many different controls. Choosing the right type gives users the right keyboard on phones, built-in validation, and accessible widgets for free.

Text-like types

  • text is the general case; maxlength limits its length.
  • email, url and tel look like text fields but bring a suitable mobile keyboard, and the first two are validated.
  • password hides what is typed.
  • search adds a clear button in some browsers.

Numbers and dates

type="number" accepts only numbers, with min, max and step limits, and offers up and down arrows. In JavaScript, valueAsNumber gives the value as a number instead of a string; the example adds 1 to it. type="date" opens a date picker and always uses the format YYYY-MM-DD in its value, whatever the display format in the visitor's locale. time, datetime-local and month work similarly.

HTML · editable

Expected page text

Name
Age
Start date
Track
Python SQL
Level
Beginner
Intermediate
Message

Choices

  • Radio buttons (type="radio") let the user pick exactly one option from a group. All radios in a group share the same name. Wrap the group in a <fieldset> with a <legend>, so screen readers announce "Track, Python, radio button, 1 of 2".
  • Checkboxes (type="checkbox") toggle independent yes/no options.
  • <select> shows a drop-down list of <option> elements, useful when there are too many choices for radios. Add selected to preselect an option, and multiple to allow several.

Multi-line text

<textarea> accepts paragraphs of text. Unlike <input>, its initial content goes between the tags, and rows sets its visible height.

What the page text shows

The expected output above is the page's visible text. Values typed into fields are not part of a page's text content, so only the labels, the legend and the option texts of the <select> appear there. Chrome lists every option, not just the selected one. Run the example to see the console line it prints from the controls' current values.

Validation attributes

required, min, max, minlength, maxlength and pattern describe valid input. checkValidity() reports whether a control currently passes them; the example's number field does, so it logs true.

Common mistakes

  • Using type="text" for everything and losing mobile keyboards and validation.
  • Giving radio buttons in a group different name values, so several can be selected.
  • Using type="number" for things like ZIP codes or card numbers, which are identifiers, not quantities. Use inputmode="numeric" on a text input instead.

Summary

  • Choose input types for meaning: email, number, date and more.
  • Radios share a name and sit in a fieldset with a legend.
  • <select> with <option> for longer lists; <textarea> for paragraphs.
  • Validation attributes describe the rules; checkValidity() tests them.

Quiz: Input types and controls

1. What must radio buttons in one group share?

Radios with the same name form a group where only one can be selected.

2. In which format does <input type="date"> store its value?

The value is always an ISO-style date; only the display is localized.

3. Which element gives a group of radio buttons an accessible name?

The legend names the fieldset that groups the controls.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.