HTML: input type="text"
A text input collects a short, single-line value such as a name, title, or search term.
What you will learn
- How to connect a label to a text input
- How to add useful constraints without hiding the purpose
- When to use a different input type or a textarea
Minimal example
<label for="display-name">Display name</label>
<input id="display-name" name="display-name" type="text"
maxlength="40" autocomplete="nickname" required>A visible label explains what the field means. Use maxlength and required only when they match the real data rules.
Common mistakes
- Do not use placeholder text as the only label.
- Use
<textarea>for multiple lines. - Choose a more specific type such as
email,url, orpasswordwhen it describes the value.