<input>
Example
<input
type="text"
placeholder="Email"><label for="email">Email</label>
<input
id="email"
name="email"
type="email"
autocomplete="email"
required>A real label, type='email' and autocomplete give a clear name, the right keyboard and autofill.
Common mistakes
- Using
placeholderinstead of a label, so the hint vanishes while typing. - Using
type='number'for phone numbers or postal codes.
Key points
- Each
<input>has a linked<label>, andplaceholderis not used as the label. - The
typematches the data, like 'email' or 'tel', to get validation and the right mobile keyboard. - Personal data fields have
autocompletevalues like 'email' or 'given-name'. - Required fields use the
requiredattribute, not only a red asterisk.
Interview questions
Should I use type='number' for phone numbers?
No, use type='tel'. number is for quantities, and it can drop leading zeros and show spin buttons.
Is a placeholder enough instead of a label?
No, the placeholder disappears while typing and is often low contrast. Use a visible <label>.