Label

Field and section labels with leading and trailing slots, required and optional marks, subtext, control inset alignment, and typography chrome.

Also known as: field label, form label, accessible label, section label

Installation

Install with the CLI, or copy the component source into your project.

Add label (npm)

npx --yes -p @default-file/ui df-ui add label

Default

Standalone label.

Required asterisk

Required mark as a red asterisk.

Required text

Required mark as red (required) text. Override with requiredColor.

Optional text

Optional mark as muted catalogue text such as (optional).

Optional asterisk

Optional mark as a muted asterisk.

With subtext

Supporting line under the title.

With counter

Trailing character count paired with an input.

Badge

Use Badge in the trailing slot to highlight a field.

Leading slot

leading is a ReactNode slot before the title. Prefer FeaturedIcon plain at size md with glyphShadow off for a bare mark that matches the leading size token. You can pass any node.

Inset left

Align the label to the control outer edge. Default.

Inset content

Align the label to the default control content start via --df-control-content-inset-inline.

Inset content with icon

Same content inset as a leading icon. First content starts at the shared control inset.

Inset custom

Set insetAlign custom with insetSize when the paired control uses a non-default content inset.

Properties

Field and section label with leading and trailing slots, required and optional marks, subtext, control inset alignment, and typography chrome. Use as="label" with htmlFor for form controls. Use as="div" for section titles that share the same chrome.

Label

Root element, title content, and slots.

PropTypeDefaultNotes
as"label" | "div""label"Root element. "label" associates with a control via htmlFor. "div" is for section titles such as SidebarGroupLabel.
htmlForstring-Id of the labeled control. Applies when as is label.
childrenReactNode-Primary title content.
leadingReactNode-Slot before the title text. Prefer FeaturedIcon plain at size md with glyphShadow off for a bare mark that matches the leading size token. Plain SVG icons still fit that token.
trailingReactNode-End-aligned slot on the title row. Pass Badge, a character count, an icon, or a control such as SidebarGroupAction.
subtextReactNode-Secondary supporting line under the title row.
classNamestring-Additional classes on the root.
styleCSSProperties-Inline styles on the root. Can set --label-required and --df-label-* chrome vars.

Inset

Horizontal inset relative to a paired control. content uses --df-control-content-inset-inline, the same default as Input and Select content start.

PropTypeDefaultNotes
insetAlign"left" | "content" | "custom""left"left aligns to the control outer edge. content aligns to the default control content start (text, or a leading icon at that inset). custom uses insetSize.
insetSizestring-Required for a non-zero custom inset when insetAlign is custom. Prefer spacing tokens such as calc(5 * var(--spacing-unit)). Sets --df-label-inset-custom.

Marks

Decorative required and optional indicators after the title.

PropTypeDefaultNotes
requiredbooleanfalseShows a decorative required mark after the title. Wins over optional when both are set.
requiredVariant"asterisk" | "text""asterisk"Required mark style. "asterisk" renders the catalogue asterisk string as-is. "text" renders the catalogue required string as-is. Color uses --label-required.
requiredColorstring-Required mark color. Prefer tokens such as var(--destructive). Sets --label-required.
optionalbooleanfalseShows a decorative optional mark after the title. Ignored when required is true.
optionalVariant"asterisk" | "text""text"Optional mark style. "text" renders the catalogue optional string as-is. "asterisk" renders the catalogue asterisk string as-is.

Typography

Title color and type. Prefer kit tokens for values.

PropTypeDefaultNotes
colorstring-Title color. Prefer tokens such as var(--muted-foreground). Sets --df-label-color.
fontFamilystring-Title font family. Sets --df-label-font.
fontSizestring-Title font size. Sets --df-label-size.
fontWeightstring-Title font weight. Sets --df-label-weight.

Parts

DOM structure markers for styling and tests. These are not component props. data-df="label": Root element. data-inset is left, content, or custom. data-df="label-row": Title row with the title group and trailing slot. data-df="label-title": Title group: leading slot, title text, and required or optional mark. data-df="label-leading": Leading slot before the title text. data-df="label-text": Primary title text. data-df="label-required": Required mark. Uses --label-required. data-variant is asterisk or text. data-df="label-optional": Optional mark. data-variant is asterisk or text. data-df="label-trailing": Trailing slot on the title row for meta, icons, or controls. Uses --df-label-row-gap between multiple trailing children. data-df="label-subtext": Supporting line under the title row.

Tokens

Theme defaults live on :root. Override these globally or on a local host.

TokenTypeDefaultNotes
--df-label-gapCSS lengthcalc(1 * var(--spacing-unit))Stack gap between the title row and subtext.
--df-label-title-gapCSS lengthcalc(1.5 * var(--spacing-unit))Gap inside the title group between leading, title text, and marks.
--df-label-row-gapCSS lengthcalc(2 * var(--spacing-unit))Gap on the title row between the title group and trailing slot, and between multiple trailing children.
--df-label-leading-sizeCSS lengthcalc(4 * var(--spacing-unit))Default width and height for SVG icons in the leading slot.
--df-label-trailing-sizeCSS lengthvar(--df-label-leading-size)Default width and height for direct SVG icons in the trailing slot. Defaults to --df-label-leading-size.
--df-label-colorCSS colorvar(--foreground)Title color. Falls back to --foreground. Override with color.
--df-label-fontCSS font-familyinheritTitle font family. Override with fontFamily.
--df-label-sizeCSS lengthvar(--df-text-sm)Title font size. Falls back to --df-text-sm. Override with fontSize.
--df-label-weightCSS font-weightvar(--df-font-weight-medium)Title font weight. Falls back to medium. Override with fontWeight.
--df-label-insetCSS length0Horizontal inset applied as padding-inline-start. Resolved from insetAlign.
--df-label-inset-contentCSS lengthvar(--df-control-content-inset-inline)Inset used when insetAlign is content. Defaults to --df-control-content-inset-inline. Input and Select field roots may override this to track their content padding.
--df-label-inset-customCSS length0Inset used when insetAlign is custom. Set by insetSize.
--df-control-content-inset-inlineCSS lengthcalc(3 * var(--spacing-unit))Shared default control content-start inset. Owned in df-tokens.css. Input, Select, Combobox, and Label content mode consume it.
--foregroundCSS colorvar(--df-neutral-900)Default title color when --df-label-color is unset.
--muted-foregroundCSS colorvar(--df-neutral-500)Optional mark, subtext, and trailing color.
--label-requiredCSS colorvar(--destructive)Required mark color. Override globally or via requiredColor.
--destructiveCSS colorvar(--df-destructive)Default source for --label-required.