HTML: input

The <input> element collects a value from a user. Its type attribute chooses the kind of control.

What you will learn

Basic text input

<label for="username">Username</label>
<input id="username" name="username" type="text">

The id connects the input to the label. The name identifies the value when the form is submitted. If type is omitted, the default is usually text.

Common types

<input type="email" name="email">
<input type="password" name="password">
<input type="number" name="age">
<input type="checkbox" name="updates" value="yes">
<input type="radio" name="plan" value="basic">

Choose the type that matches the data. Browsers can provide suitable controls, validation, and mobile keyboards.

Useful attributes

Attributes such as required, disabled, placeholder, min, max, and autocomplete change behavior or provide hints. Do not use a placeholder as the only label.

Common mistakes