# Label

Names a form control, and focuses it when pressed.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/label shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

- **In a field**: `dex-field-label` over the control, joined with `for` and `id`.

```html
<div class="dex-form-row">
  <label class="dex-field-label" for="notice">Notice period</label>
  <input class="dex-field" id="notice" placeholder="1 month" />
</div>
```

- **Around a checkbox, radio or switch**: a `dex-check-row` label wrapped round the control needs no `for`.

```html
<label class="dex-check-row"><input type="checkbox" class="dex-checkbox" /> Open to contract roles</label>
```

- **With a switch in a settings row**: the label on the left, joined with `for`, and the switch on the right. See https://brand.meetdex.ai/components/switch.md.
- **Optional**: "(optional)" after the label, muted: `<span class="dex-muted">(optional)</span>`.
- **For a group**: one question over several options is a `<legend>` in a `<fieldset>`, not a label. `dex.css` doesn't reset the fieldset's browser border, so do it yourself:

```html
<fieldset style="border: 0; margin: 0; padding: 0; display: grid; gap: 0.75rem">
  <legend class="dex-field-label" style="margin-bottom: 0.75rem">How soon could you start?</legend>
  <label class="dex-check-row"><input type="radio" name="start" class="dex-radio" /> Straight away</label>
  <label class="dex-check-row"><input type="radio" name="start" class="dex-radio" /> Within a month</label>
</fieldset>
```

- **Disabled**: a disabled field dims its label with its control (`style="opacity: 0.5"` on the label).

## Rules

- Every control has a label. One label names one control; for one question with several options, use a legend.
- A label pressed focuses its control, or ticks it. Join it with `for` and `id`, or wrap the control in it.
- Mark a field that can be left empty as optional. Don't mark required ones.
- The label keeps its colour when the field has an error. Only the control's edge and the message turn red.
- Labels are sentence case, with no colon and no full stop.
