← Web basics: HTML, CSS and JavaScript

Input types

email, number, password, checkbox, radio and more.

Start this lesson

The type attribute changes what an input is. type="email" checks for an @ and shows an email keyboard on phones. type="number" shows a number pad and accepts min and max. type="password" hides what is typed. type="checkbox" is a box to tick on or off, and type="radio" is a choice of one from a group (all radios in a group share the same name). For longer text, use <textarea>, and for a drop-down list, use <select> with <option> elements inside.

<label for="mail">Email</label>
<input id="mail" name="mail" type="email">

<label for="tickets">Tickets (1 to 6)</label>
<input id="tickets" name="tickets" type="number" min="1" max="6">

<p>Seat:</p>
<label><input type="radio" name="seat" value="window"> Window</label>
<label><input type="radio" name="seat" value="aisle"> Aisle</label>

<label><input type="checkbox" name="news"> Send me news</label>

The two radios share name="seat", so choosing one un-chooses the other. Each has a value, which is what gets sent. The checkbox stands alone: on or off.

If you leave out type, the input is type="text".

Choosing the right type is free help: phones show the right keyboard and the browser checks simple mistakes before the form is sent.