HTML: input
The <input> element collects a value from a user. Its type attribute chooses the kind of control.
What you will learn
- How common input types differ
- Why every control needs a useful label
- How name, id, and value affect form submission
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
- Do not omit a meaningful label for an input.
- Controls without a
nameare generally not included in form data. - Use a shared
namefor radio buttons that represent one choice group.