Label
Accessible form labels. Link text to inputs. Boost completion rates.
Installation
Copy and paste the following code into your project.
Update the import paths to match your project structure.
Anatomy
Variants
Default
A label paired with an input.
Required & Optional
Use
required to show a red asterisk, optional to show "(optional)" text, and description for helper text.The asterisk is only visual. Put
required on the input as well, so screen readers announce it from the control itself.The description gets the id
{htmlFor}-label-description, or the one you pass in descriptionId. Point the input's aria-describedby at it so the hint is read along with the field.Printed on every invoice we send you.
API Reference
Label
| Prop | Type | Default | Description |
|---|---|---|---|
required | boolean | โ | Shows a red * indicator next to the label text. |
optional | boolean | โ | Shows "(optional)" text next to the label. |
description | string | โ | Helper text displayed below the label. |
descriptionId | string | {htmlFor}-label-description | Id of the description, for the input's aria-describedby. |
htmlFor | string | โ | Associates the label with a form element. |
className | string | โ | Additional CSS class names. |
children | React.ReactNode | โ | The label content. |
Found something to improve?
Notice a bug, typo, or missing detail on this page? Help us make the documentation better by opening a GitHub issue.