HTML input types
- closing tag
- none — void element
- void element
- yes
- lives inside
- <form>, next to its <label>
- typically holds
- n/a (self-contained)
Where it goes
On every <input>, even though text is the default. Pair it with a <label> whose for matches the input's id. Checkbox and radio fields also need the label's text, so the visitor has something to click.
Example
<label for="e">Email</label>
<input type="email" id="e" name="email" required>
<label><input type="checkbox" name="tos"> I agree</label>
<input type="radio" name="size" value="s" id="s"> <label for="s">Small</label>
<input type="radio" name="size" value="l" id="l"> <label for="l">Large</label>Open this example in the editor →
Common mistakes
- Using type="text" for everything. You lose the phone keyboard switch, the free checks and the built-in date and color pickers.
- Using type="number" for things that are not amounts, like phone numbers or zip codes. It drops leading zeros and shows a spinner. Use type="tel", or text with inputmode="numeric".
- Giving the radio buttons in one group different name values. The browser only treats inputs with the same name as one group, so more than one can be picked.