StartFoundationsComponentsContent

Input

An input takes one line of text, such as a name, an email, or a URL. It is a bare box; wrap it in a Field to give it a label, help text, and errors.

Stable Figma
OverviewUsageAPIAccessibility
<tk-field label="Email address" helper="We only use this for the receipt">
  <tk-input type="email" name="email" autocomplete="email"></tk-input>
</tk-field>

Anatomy

Part What it is
tk-input the element; one Tab stop
field part the bordered box
input part the native <input> inside
prefix slot optional text or icon before the value
suffix slot optional text or icon after the value

The label, help text, and error message come from a Field, not from the input.

Sizes

<tk-input aria-label="Medium input" value="Medium"></tk-input>
<tk-input aria-label="Large input" size="large" value="Large"></tk-input>
size Height Padding-inline Value text
medium (default) 32px space-8 Body Small (14/20)
large 36px space-10 Body Medium (16/24)
  • The heights match medium and large buttons, so a field and its button line up.
  • There is no small. size="small" renders as medium and logs a console warning.
  • The input fills its container's width. Size the container to the expected answer: a postcode field is postcode-sized.

States

<tk-input aria-label="Workspace URL" value="acme.thykes.com" readonly></tk-input>
<tk-input aria-label="Company" value="Acme Inc." disabled></tk-input>
<tk-field label="Email address" required error="Enter an email address, like name@example.com">
  <tk-input type="email" name="email" value="ada@"></tk-input>
</tk-field>

The box doesn't change on hover. On focus, its border takes the focus color and grows thicker inward, so nothing moves.

  • readonly: people can focus the input and select or copy its value, but not edit it. It looks like content. Use it for values people may need to read or copy.
  • disabled: the input can't be focused or edited, and it's left out of the form. Prefer readonly, or keep the field active. If a field can't change, say why in the help text.
  • Error: set error on the Field. The message shows under the box, the border turns red, and it stays red while the field has focus.
  • Required: set required on the Field. It marks the label with an asterisk and makes the input required. Without a Field, set required on the input.

The input doesn't check what people type, apart from the browser's own checks (required, the type format, maxlength). You decide when to validate and what the error says.

Label, help text, and errors

<tk-field label="Card number" helper="The 16 digits on the front of your card">
  <tk-input inputmode="numeric" name="card" autocomplete="cc-number"></tk-input>
</tk-field>
<tk-input aria-label="Filter by name"></tk-input>
  • Wrap the input in a Field for a label, help text, or an error. The Field names the input for screen readers.
  • Inside a Field, set required and disabled on the Field. The Field overrides them on the input.
  • Without a visible label, set aria-label (or aria-labelledby) on the input. Use it only when the purpose is clear from what's around the field.
  • Every input needs one or the other. A placeholder is never a label.

Prefix and suffix

@ .thykes.com
<tk-field label="Username">
  <tk-input name="username"><span slot="prefix">@</span></tk-input>
</tk-field>
<tk-field label="Workspace address">
  <tk-input name="workspace"><span slot="suffix">.thykes.com</span></tk-input>
</tk-field>
<tk-field label="Website">
  <tk-input type="url" name="website"><tk-icon slot="prefix" name="link"></tk-icon></tk-input>
</tk-field>
  • Use prefix for the kind of value (@, $, an icon) and suffix for a unit or domain (USD, .example.com). One short text or one tk-icon each.
  • Affixes are hidden from screen readers. Don't put information there that the label or help text doesn't also give.
  • Affixes are decoration. Don't put buttons in them; there is no clear button, character counter, or show-password toggle.