Label
A styled form label associated with a control via for, with an optional
required marker.
Import
Section titled “Import”<script> import Label from "@invisible-ui/svelte/Label.svelte";</script><script setup> import { Label } from "@invisible-ui/vue";</script>import { Label } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-label></ds-label>| Prop | Type | Default | Description |
|---|---|---|---|
required | boolean | false | Show a * required marker. |
| Prop | Type | Default | Description |
|---|---|---|---|
for | string | undefined | Id of the control this labels (sets for). |
required | boolean | false | Show a required marker (*) after the text. |
Slots: default.
| Prop | Type | Default | Description |
|---|---|---|---|
htmlFor | string | — | Id of the control this labels. |
required | boolean | false | Show a required marker (*), hidden from assistive tech, after the text. |
children | ReactNode | — | The label text. |
| Attribute | Reactive | Description |
|---|---|---|
for | yes | id of the control |
required | yes |
Reactive attributes re-render the element when they change after the first render.
The label text is the default slot.
Example
Section titled “Example”<Label for="email" required>Email</Label><input id="email" type="email" />In React, htmlFor names the control, and useLabel gives the same props to
a label of your own:
<Label htmlFor="email" required> Email</Label><input id="email" type="email" />Themeable via --ds-label-*.