<input>

Term side of the Card.
Topic: Forms
Unit title: <input>
Categories: Tag
Explanation side of the Card

Explanation: The element that is used to create interactive controls for forms, allowing users to enter data. It supports various types, such as text fields, checkboxes, radio buttons and file uploads, making it a key element in form interactions.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wronghtml
<input
  type="text"
  placeholder="Email">
Righthtml
<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 placeholder instead 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>, and placeholder is not used as the label.
  • The type matches the data, like 'email' or 'tel', to get validation and the right mobile keyboard.
  • Personal data fields have autocomplete values like 'email' or 'given-name'.
  • Required fields use the required attribute, 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>.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy