Forms
Label
The label of a form field: the text above the control, with optional icon, badge, help icon and content on either side, such as a "Forgot password?" link. Every form control renders it from its label prop; use the tag directly for a control of your own.
Nothing to show
A <label for="nickname"> with "Nickname" in semibold, in the strong text color. Clicking it focuses the input, as a native label does. The label gets the id nickname-label, for an aria-labelledby elsewhere.
Content beside the label #
"Password" at the start of the line and the link at the end. labelPrepend places content before the label in the same way.
Nothing to show
Badge and help icon #
The label is followed by an "Optional" badge and a help icon whose tooltip shows the text. Both are props of the field, passed on to its label.
Nothing to show
Visible only to screen readers #
The label is not shown, but screen readers still announce the input as "Search".
Nothing to show
Sizes #
size sets the text size, from xs to 3xl.
Nothing to show
Icon #
The element props work on the label: icon puts an icon before the text.
Nothing to show
Before and after the label #
tk:label takes the labelPrepend and labelAppend slots itself: here an icon before the text and a counter at the end of the line.
Nothing to show
Label attributes from a field #
A form control passes its label: attributes to its label.
Nothing to show
Customization #
Classes go to the element that holds the text; container:, label-append: and info: reach the other parts.
Nothing to show
Reference
tk:label
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string | slot | null |
The text, translated. The default slot takes its place. |
for |
string | null |
The id of the control. Makes the label a <label for> and gives it the id <for>-label. |
as |
string | label with for, span without |
The element to render. |
labelPrepend |
slot | null |
Content at the start of the line, before the label. |
labelAppend |
slot | null |
Content at the end of the line, after the label. |
size |
string | md |
xs, sm, md, lg, xl, 2xl or 3xl. |
srOnly |
bool | false |
Hides the label visually, keeping it for screen readers. |
info |
string | slot | null |
A help icon after the label, with this text as its tooltip. |
Also accepts the element props (icon, badge, suffix...).
Slots
| Slot | Description |
|---|---|
| default | The text, in place of label. |
labelPrepend |
Content before the label. |
labelAppend |
Content after the label. |
Prefixes
| Prefix | Goes to |
|---|---|
container: |
The <label> (or <span>) element. |
area: |
The row holding the label and the prepend or append content, when there is any. |
label-prepend: |
The prepend content. |
label-append: |
The append content. |
info: |
The help icon. |
Customization
Classes and attributes go to the inner element that holds the text. To reach the other parts, prefix the attribute (listed in the Reference above).
From a field, the label takes the label: prefix: <tk:input name="email" label:class="text-lg" />.
Accessibility
With for, a native <label> linked to the control. Without it (a <span>), clicking the label still focuses the control of the same field, checks a checkbox, or picks a radio; but it does not name the control, so give the control an aria-labelledby pointing to the label.
Behavior notes
- With no label and no slot content, nothing is rendered, including the prepend and append content.