Search docs

Label

A label for a form control.

There is no WAI-ARIA APG pattern for labels. Label renders a native <label>, which names the control it is associated with.

import { component$, useStyles$ } from '@builder.io/qwik';
import { Label } from '@leve-ui/label';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <div class="label-default-field">
      <Label.Root for="email" class="label-default">
        Email
      </Label.Root>
      <input id="email" type="email" placeholder="[email protected]" class="label-default-input" />
    </div>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/label

Anatomy#

import { Label } from '@leve-ui/label'; // or '@leve-ui/core'

<Label.Root />
PartElementDescription
Label.Root<label>The label. Associate it with a control with for, or by wrapping the control.

Examples#

Wrapping#

Wrapping a control in Label.Root associates them without for and id.

API Reference#

Root#

No props of its own. Accepts all <label> attributes.

Data attributeValue
data-leve-labelAlways present

All props, including for, are passed to the native <label>. Inside a Field, use Field.Label instead: it is associated with the control automatically.

Accessibility#

  • The label becomes the accessible name of the associated control. Set for to the control's id, or wrap the control in the label.
  • Clicking the label focuses the control, or toggles it when it is a checkbox or radio button.
  • Label has no keyboard interaction.