Label
The visible name of a form control: 14px medium text that stays on screen while the user types. Marks a required field with a quiet Required note at the end of its row, or an optional one with Optional, can start with a decorative icon, and can add an info button with a tooltip for extra help. Inside a Field, use FieldLabel, which points at the control on its own.
Preview
Usage
When to use
- Name a form control with text that stays on screen while the user types.
- Mark a required field, or an optional one in a form where most fields are required.
When not to use
- A control with a description or an error. Use Field, which links them to the control and sets the label for you.
- Text that names no control, such as the title of a section. Use a heading.
- Replacing it with a placeholder, which disappears as soon as the user types.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| htmlFor | Yes | No | No | Only on web. Not generated for iOS and Android. |
| leadingIcon | Yes | Yes | Yes | |
| required | Yes | Yes | Yes | |
| optional | Yes | Yes | Yes | |
| requiredText | Yes | Yes | Yes | |
| optionalText | Yes | Yes | Yes | |
| disabled | Yes | Yes | Yes | |
| tooltip | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| tooltipLabel | Yes | Deferred | Deferred | Not generated for iOS and Android. |
Examples
Default
Required
The Required note is for sighted users; required on the input is what screen readers announce.
Optional
Disabled
With a leading icon
The icon is decorative; the label text names the field.
With a tooltip
The info button names the field, and its tooltip is read as the button's description.
Do and don't
Do
- Give every form control a visible label, above it or beside it.
- Write the name in sentence case without a colon: Email, Project name.
- Prefer Field, which wires the label, the control, its description and its error.
- Mark the few required fields when most are optional, or the few optional ones when most are required.
- Use the tooltip for help some users need, such as where to find a value; name its button with the field: About API keys.
- Next to a checkbox, use its label and description props; they lay out the row and link the ids.
Don't
- Don't use a placeholder or aria-label instead of a visible label.
- Don't mark both required and optional fields in one form.
- Don't put a label on text that names no control; use a heading or a paragraph.
- Don't hide what every user needs in the tooltip; write it in the field's description.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| htmlFor | string | - | - | The id of the control this label names. FieldLabel sets it for you. Only on web. Not generated for iOS and Android. |
| leadingIcon | node | - | - | Decorative Tabler icon before the label, size={16}. Hidden from screen readers: the label text names the field. |
| required | boolean | - | false | Shows a Required note at the end of the row. Also set required on the control. Can't be combined with optional. |
| optional | boolean | - | false | Shows an Optional note at the end of the row, for a form where most fields are required. Mark the few required fields or the few optional ones, not both. |
| requiredText | node | - | Required | The Required note, for a page in another language. |
| optionalText | node | - | Optional | The Optional note, for a page in another language. |
| disabled | boolean | - | false | Dims the label to match a disabled control. Sets data-disabled. |
| tooltip | node | - | - | Extra help behind an info button after the label, such as where to find a value. A few words of plain text. Needs tooltipLabel. Not generated for iOS and Android. |
| tooltipLabel | string | - | - | Name of the info button, with the field in it: About API keys. Required with tooltip. Not generated for iOS and Android. |
Slots
| Name | Required | Description |
|---|---|---|
| label | yes | The name of the field, in sentence case and without a colon: Email, Project name. |
Anatomy
| Part | Description |
|---|---|
| root | The label element: 14px medium secondary text, so the value in the control stays louder. A Required or Optional note sits at the end of the row. With a tooltip, the root is a row that holds the label and the info button. |
| icon | Optional decorative Tabler icon before the text, 16px, in the secondary icon color, level with the first line. Hidden from screen readers. |
| marker | The Required note: 12px regular tertiary text at the end of the row (ms-auto), hidden from screen readers. |
| optional | The Optional note: the same quiet text as Required, read with the label. |
| info | Optional info button after the label: a size-icon-lg circle (20px) around a 16px Tabler info icon in the secondary icon color, neutral hover and pressed overlays, focus ring. Opens the tooltip. The hit area still grows to size-target-min. |
| hitArea | Transparent ::before centered on the info button, never smaller than size-target-min (24px on mouse, 44px on touch). |
Accessibility
Role: generic
| Keys | Action |
|---|---|
| Tab | With tooltip: moves focus to the info button and opens the tooltip. |
| Enter, Space | With tooltip: opens or closes the tooltip. |
| Escape | With tooltip: closes the tooltip. |
- htmlFor must match the id of the control, so a press on the label focuses the control and screen readers read the label as its name. Inside a Field, FieldLabel sets it.
- The Required note is text, so it never relies on color, and it is hidden from screen readers. Set required on the control too: that is what screen readers announce.
- The Optional note stays in the accessible name, since no attribute says a field is optional.
- A placeholder is not a label: it disappears as soon as the user types.
- The info button sits outside the label element, so its name never becomes part of the control's name. The type requires tooltipLabel with tooltip, and the label should include the field: About API keys.
- The tooltip opens on hover and focus, and a press toggles it, so it works on touch screens too. Its text is read as the button's description.
- Keep what the user needs to fill the field in a description under it (FieldDescription), not only in the tooltip.
Install
npx werewolf-ui add labelRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.