Label
Names a form control. A click on it focuses the control, and a screen reader reads it.
When to use
- Name any form control: an input, a select, a checkbox, a switch.
When not to use
- A label with a description and an error under it: use
FieldLabelinside Field. - A title for a group of controls, such as a set of radio buttons: use
FieldLegendinsideFieldSet. - A heading for a section: use a heading element.
Install
npx shadcn@latest add @clinia/labelClinia rules
- Labels are 14px medium, sentence case, and name the value:
Workspace name, notPlease enter your workspace name:. No trailing colon. - When its control is disabled, the label fades to 50% with it: put the control first as a
peer, or both in a group withdata-disabled="true".
Do and don't
States
default
beside a disabled control
Toggle the site theme to review both themes.
Accessibility
Your responsibility
- Set
htmlForto the control'sid, or wrap the control in the label. A label that points nowhere names nothing. - Keep the label visible. A placeholder is not a label: it disappears as soon as the user types.
How to test
- Click the label: focus moves to its control, and a checkbox or switch toggles.
- With a screen reader, Tab to the control: it's announced with the label's text.
API
Every prop comes from the native label element.