Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Forms

Label

A styled text label linked to a form control, with a required marker.

Selector: mui-label

Import
import { Label } from '@mushilu-san/ui/forms';
PreviewCode

Loading example…

Overview

Label renders a native <label> and links it to the control with for. Clicking the label focuses the control, and screen readers read the label as the control name.

Set required to show the required marker. The marker is decorative (aria-hidden), so also mark the control itself with required.

When to use

  • Naming any form control that is not wrapped in a Form field.
  • Labelling a custom control while keeping the same styling as other labels.

When not to use

  • A whole field with a hint and error message. Use a Form field, which includes the label. Use Form field instead.

Guidelines

Do

  • Keep labels short and visible at all times.
  • Put the label above the control.

Don't

  • Do not use a placeholder in place of a label.
  • Do not use the required marker alone. Explain what required means if it is not obvious.

Accessibility

Roles and attributes

ElementRoleNotes
label—Native label. The required mark is aria-hidden="true".
  • A label is not focusable. Clicking it moves focus to the linked control.

API

Label

Selector: mui-label

NameTypeDefaultDescription
forstring | undefined— Id of the control this label names. Sets the `for` attribute.
requiredbooleanfalse Shows a required marker after the text. The marker is decorative; set `required` on the control too. Accepts attribute presence, e.g. <… required>.
disabledbooleanfalse Dims the label to match a disabled control. Accepts attribute presence, e.g. <… disabled>.

CSS parts

  • ::part(root)

Tokens

  • --mui-color-text
  • --mui-color-text-muted
  • --mui-font-weight-medium
  • --mui-color-danger