Skip to content

role textbox

Text field draft v0.1.0

Lets people enter or edit a single line of text.

A text field collects one line of free text: a name, an email address, a search term, a quantity typed as text. It has a visible label above, an optional description and, when its value fails validation, an error message under it. Several lines of text are a Textarea; a choice among known values is a Select.

Guidelines

From apps/docs/content/components/text-field.md

Overview

A text field collects one line of free text: a name, an email address, a search term. It is the most common form control, and the one whose details matter most: a visible label above the box, help text under it when the expected format is not obvious, and an error message that says how to fix the value when validation fails.

This page applies to every platform. Where a platform differs, the difference sits under a sub-heading named after it (Web, iOS, Android, Desktop); everything else holds everywhere.

When to use

  • Free text that fits on one line: names, email addresses, identifiers, short answers.
  • A value that people type rather than choose, even when a format is expected (a phone number).

When not to use

  • Several lines of text. Use a Textarea.
  • A choice among known values. Use a Select, or a Radio group for a few options.
  • A yes / no value. Use a Checkbox or a Switch.

Sizes

Size Use for
Small Dense forms, toolbars and table rows: 32 px high with 14 px text.
Medium Forms, the default: 40 px high with 16 px text.
Large A prominent single field, such as a search page or a sign-in form: 48 px high with 20 px text.

Height, inline padding and text size scale together; the label, the description and the error message keep one size. The exact values are tokens (Tokens tab). Keep one size per form.

Label, description and placeholder

The label names the information asked for and is always visible, above the box. The description, under the box, gives the format, an example or what the value is used for. The placeholder is a hint inside the empty box, in a lighter color: it disappears as soon as people type, so it never replaces the label and never carries an instruction people must remember.

States

State How it happens What changes
Default Resting. An outlined box on the default surface.
Hover A pointer rests over the box. Needs a pointing device: there is no hover on touch. The box takes the surface hover tint; the border does not change.
Focus visible The box has focus, from the keyboard or a pointer. The shared focus ring appears outside the border. An editable field shows it however it was focused.
Invalid invalid property, after validation. The border takes the error color and the error message appears under the box.
Read-only readonly property. The box takes the level 1 surface; the value can still be focused, read and copied.
Disabled disabled property. Box, value, label and description drop to the shared disabled colors; the field leaves the keyboard order.

Invalid and hover combine (the hover tint under the error border), and disabled wins over every other state: the states matrix shows what the tokens decide.

Content

  • The label is a noun phrase: Email address, Company name. Sentence case, no colon, no trailing punctuation.
  • The description gives the format or an example when it is not obvious.
  • The placeholder, when any, is a short example of a valid value (name@example.com).
  • The error message says what is wrong and how to fix it: Enter an email address with an @.

Accessibility

The Specification tab lists the full accessibility contract, grouped into what holds on every platform and what is specific to one. Each statement there links the source it comes from. This section explains the decisions behind it.

Web

  • The implementation renders an <input type="text"> in a wrapper with a <label for>, a description and an error message referenced by aria-describedby, aria-invalid="true" when invalid, and the native required and readonly attributes (ARIA in HTML: input type=text, HTML-AAM: input type=text, ARIA1, ARIA21, HTML: readonly).
  • The HTML standard says the placeholder is not an alternative to a label, and the WAI tutorial explains why: it disappears when people start typing (HTML: placeholder, WAI tutorial: placeholder text).
  • The input type (email, tel, url) and the autocomplete token are passed through the template’s extra attributes; they change the keyboard and the browser’s help, not the look.
  • The focus ring uses :focus-visible, which browsers match whenever an editable field has focus (MDN: :focus-visible); the transition is switched off under prefers-reduced-motion.

iOS

Android

  • Textarea (several lines of text)
  • Select (a choice among known values)