# Label

Names a control. Built on ui-sdk's Label: point htmlFor at the control's id and a press on the label focuses it, for any control, not only native inputs.

- Beta: ready to use; its API can still change in a minor release.
- Category: Form fields

```tsx
import { Label } from "@leap-crm/design-system";
```

## Best practices

- Do: Use `Field`'s `label` for a form control. Use `Label` on its own only for a control outside a `Field`, and point `htmlFor` at the control's id.
- Do: Mark the control itself `required` as well. The label's asterisk is visual only, so a screen reader learns it from the control.
- Do: Set `optional` on the few fields a lawyer can skip when most of a form is required. Screen readers hear "Optional" as part of the name.
- Don't: Type the asterisk or "(optional)" into the label text. Use `required` or `optional`, so every form shows them the same way.
- Don't: Use a placeholder instead of a label. It disappears once someone types, and the control loses its name.

## Related

- [Field](./field.md)
- [Eyebrow](./eyebrow.md)

## Examples

What the examples import:

```tsx
import { Label } from "@leap-crm/design-system";
```

### Variants

Required shows the red asterisk; mark the control required too, since the asterisk is hidden from screen readers. Optional shows a muted Optional, which is read as part of the name.

```tsx
<div className="flex flex-col gap-4">
  <Label>Full name</Label>
  <Label required>Full name</Label>
  <Label optional>Phone</Label>
</div>
```

### With a control

Press the label: focus moves to the field. The field is a stand-in until Input is ported.

```tsx
<div className="flex w-72 flex-col gap-2">
  <Label htmlFor="docs-email" required>
    Email
  </Label>
  <input
    id="docs-email"
    required
    type="email"
    defaultValue="jane@citizen.com.au"
    className="border-neutral-border focus-visible:border-focus-border focus-visible:shadow-focus h-9 rounded-md border px-3 text-base outline-none"
  />
</div>
```

## Props

Also takes every prop of ui-sdk's Label, including htmlFor.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `required` | `boolean` | `false` | Shows the red asterisk. Mark the control itself required too; the asterisk is visual only. |
| `optional` | `boolean` | `false` | Shows a muted "Optional", which screen readers hear as part of the name. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
