Skip to main content
Official government website

Input

Lets users enter a single line of short, free-form text.

Examples
HTML and React
Group
Form elements
On this page

Preview

Input with hint text
Open in new tab

The Input component lets users enter a single line of short, free-form text, such as a name, reference number, or email address. Every input is paired with a visible label so it is clear what answer is expected.

Usage

When to use

  • Use an input for a short, single-line answer that users know or may paste, such as a name or reference number.
  • Use the input type and width that match the value being collected.

When not to use

  • Do not use a single-line input for a long response; use a text area.
  • Do not make users type an answer when a short, predictable set of choices would be easier.

Best practices

Use a visible, persistent label

Place a short label above the input and use hint text for format requirements or examples. Do not use placeholder text as the only instruction because it disappears when users type.

Match browser behaviour to the answer

Use email, tel, url and relevant autocomplete values where appropriate. Use inputmode="numeric" with a text input for identifiers, telephone numbers and other digit strings that are not quantities.

Labels and hint text

Always pair an input with a visible <label>. Never rely on placeholder text as a label, because placeholder text disappears as soon as the user starts typing and is easy to miss altogether. Use hint text (.govbb-hint) beneath the label to explain a format or give an example, such as “As it appears on your ID”, and link it to the input with aria-describedby. We don’t use placeholder text at all — see why we don’t use placeholder text.

Choosing the right type

Pick the type attribute that matches the expected answer (email, tel, url, or password) so mobile keyboards and built-in validation behave correctly. Avoid type="number" on a plain input; use the dedicated number input component instead when you need step controls.

Prefixes and suffixes

Use a prefix or suffix to show a unit or currency, such as “$” or “per day”, so users do not type it themselves. Keep it to a symbol or one or two words: the adornment does not shrink, so a long one takes width from the field. Mark it aria-hidden="true" and make sure the label or hint carries its meaning, for example “Fee, in dollars per day”. When there is no room for the field beside them, the adornments move onto rows of their own.

Input with a prefix and suffix
Open in new tab

Errors

When an input fails validation, show an error message (.govbb-error-message) above the input with role="alert", and mark the input itself with aria-invalid="true" and aria-describedby pointing at the error message id. Keep error messages specific and actionable: say what correct looks like, such as “Enter an email address in the correct format, like name@example.com”, rather than calling the answer invalid.

Input with error
Open in new tab

Disabled inputs

Avoid disabling inputs wherever possible. A disabled input gives the user no information about what they need to do to enable it, and its content is skipped by many screen readers. Prefer showing the value as read-only text, or explaining why the field is unavailable.

Disabled input
Open in new tab