DevAcademy
LearnHTMLInput Types
IntermediateHTML

Input Types

Explore the many HTML5 input types available, each providing tailored keyboards and built-in behavior.

Reading Time

16 min

Lesson

Lesson 15 of 27

The type Attribute

The <input> element’s type attribute determines what kind of data it collects and how the browser renders it. HTML5 introduced many specialized types beyond plain text.

Common Input Types

TypePurpose
textSingle-line free text
emailEmail address, validated and shows an @ keyboard on mobile
passwordMasks the entered characters
numberNumeric input with increment/decrement controls
checkboxA single on/off toggle
radioOne choice among a group with the same name
dateA date picker
fileUploads a file from the device
rangeA slider between a min and max value
searchA text field styled and behaving like a search box
telA telephone number, shows a numeric keypad on mobile
urlA web address, validated for URL format
colorA color picker

Input Type Examples

<input type="email" name="email" />
<input type="password" name="password" />
<input type="number" name="quantity" min="1" max="10" />
<input type="date" name="birthday" />
<input type="range" name="volume" min="0" max="100" />
<input type="color" name="theme" />
Output

Checkboxes and Radio Buttons

Checkboxes allow multiple independent selections, while radio buttons restrict selection to one option per group. Radio buttons are grouped by sharing the same name attribute.

Checkbox vs Radio

<!-- Checkboxes: any number can be checked -->
<label><input type="checkbox" name="topping" value="cheese" /> Cheese</label>
<label><input type="checkbox" name="topping" value="olives" /> Olives</label>

<!-- Radio buttons: only one can be selected per name -->
<label><input type="radio" name="size" value="small" /> Small</label>
<label><input type="radio" name="size" value="large" /> Large</label>
Output

File Uploads

The file type lets users select one or more files to upload. The accept attribute restricts which file types are shown, and multiple allows selecting several files at once.

File Input

<input type="file" accept="image/png, image/jpeg" multiple />
Output

Mobile Keyboards

Using the correct input type (email, tel, number, url) automatically shows the most appropriate keyboard layout on mobile devices, improving the user experience without any JavaScript.

Best Practice

Always choose the most specific input type available for the data you’re collecting — it improves usability, gives free client-side validation, and requires no extra code.

Interview Questions

Quick Quiz

1. Which input type masks the characters the user types?

2. How are radio buttons grouped so only one can be selected?

3. Which attribute restricts which file types can be selected in a file input?