# Fieldset

Group unrelated controls under one native legend. (CSS only.)

Reference: https://timeless.build/docs/components/fieldset/

> **Choosing between components.** Use Fieldset to group controls that are not one field — an address block, a billing section. For a set of radios or checkboxes that answer one question, [Checkbox Group](/docs/components/checkbox-group/) and [Radio Group](/docs/components/radio-group/) sit on `.ui-choice-group`, which strips the native chrome because the set reads as a single field.

> **Markup you author.** Keep the `<legend>` the first child: that is what makes the browser treat it as the group name, and no ARIA substitutes for it. Native `disabled` on the `<fieldset>` disables and un-submits everything inside it, including form-associated custom elements, which is why the group needs no disabled attribute of its own.

## Markup

```html
<fieldset class="ui-fieldset" aria-describedby="billing-description">
  <legend>Billing address</legend>
  <p id="billing-description" data-ui-part="description">Used on every invoice for this workspace.</p>
  <div class="ui-field">
  <label class="ui-label" for="billing-street">Street</label>
  <div data-ui-part="control">
    <input class="ui-input" id="billing-street" name="street" type="text" placeholder="12 Copperfield Way">
    
  </div>
</div>
  <div class="ui-field">
  <label class="ui-label" for="billing-city">City</label>
  <div data-ui-part="control">
    <input class="ui-input" id="billing-city" name="city" type="text">
    
  </div>
</div>
  
</fieldset>
```

## Install

```js
import '@timelessui/components/css/tokens.css'
import '@timelessui/components/css/core/forms.css'
import '@timelessui/components/css/themes/atmosphere/tokens.css'
import '@timelessui/components/css/themes/atmosphere/forms.css'
```

## Anatomy

Parts are authored in your own markup and identified by the selector below. Required parts
must be present for the component to work. Private `data-ui-internal-*` hooks are written by
the runtime and must never be authored.

**ui-fieldset**

| Part | Required | Selector | Purpose |
| --- | --- | --- | --- |
| `legend` | Yes | `legend` | The native `<legend>`, which names the group. Keep it the first child, because that is what makes the browser treat it as the group label. |
| `description` | No | `[data-ui-part~='description']` | Group-level help text under the legend. |
| `error` | No | `[data-ui-part~='error']` | Group-level validation message. |

**ui-field**

| Part | Required | Selector | Purpose |
| --- | --- | --- | --- |
| `control` | No | `[data-ui-part~='control']` | Wrapper around the native control when one is needed. |

## Attributes

Every value below is implemented by the stylesheets this component ships. Boolean attributes
are presence-based: author the attribute with no value, or omit it.

**ui-fieldset**

| Attribute | Values | Default | Description |
| --- | --- | --- | --- |
| `data-ui-density` | `compact` · `normal` · `spacious` | `normal` | Gap between grouped controls, and the padding around them. |

**ui-field**

| Attribute | Values | Default | Description |
| --- | --- | --- | --- |
| `data-ui-layout` | `stacked` · `inline` | `stacked` | Whether the label sits above the control or beside it. |
| `data-ui-density` | `compact` · `normal` · `spacious` | `normal` | Gap between label, control, description, and error. |

**ui-input**

| Attribute | Values | Default | Description |
| --- | --- | --- | --- |
| `data-ui-size` | `sm` · `md` · `lg` | `md` | Control height, padding, and font size. |

## State

Native attributes, ARIA, and platform pseudo-classes are authoritative. Style state through
the selectors below rather than adding your own state classes.

| State | Source | How to express it |
| --- | --- | --- |
| `invalid` | aria | Set `aria-invalid="true"` on the `<fieldset>` and point `aria-describedby` at the error part. |
| `disabled` | native | Native `disabled` on the `<fieldset>`, which the browser propagates to every control inside it. |
| `invalid` | aria | Set `aria-invalid="true"` on the control and point `aria-describedby` at the error part. |
| `invalid` | native | Native `:invalid`, or `aria-invalid="true"`. |
| `disabled` | native | Native `disabled`. |

## Styling

Root identity: `ui-fieldset`, `ui-field`, `ui-label`, `ui-input`, `ui-description`.
Required stylesheets: `tokens.css`, `core/forms.css`, `themes/atmosphere/tokens.css`, `themes/atmosphere/forms.css`.

This component adds no custom properties of its own. Restyle it through the design tokens at https://timeless.build/docs/styling/theming/ or your own CSS.

Design tokens this component reads (26), global and set at the theme level: `--ui-accent`, `--ui-bg-control`, `--ui-bg-control-muted`, `--ui-bg-surface`, `--ui-bg-surface-subtle`, `--ui-danger`, `--ui-danger-soft`, `--ui-disabled-opacity`, `--ui-duration-fast`, `--ui-ease-standard`, `--ui-fg`, `--ui-fg-muted`, `--ui-fg-subtle`, `--ui-focus`, `--ui-line`, `--ui-line-strong`, `--ui-radius-md`, `--ui-radius-pill`, `--ui-radius-sm`, `--ui-shadow-control`, `--ui-shadow-inset`, `--ui-space-1`, `--ui-space-2`, `--ui-space-3`, `--ui-space-4`, `--ui-space-5`.

## Accessibility

Keep the native elements, roles, and relationships shown in the markup. Timeless adds only the
state and keyboard coordination the platform does not already provide, and it never supplies
your accessible names — those depend on your content.

This component declares no keyboard contract, because it has none of its own: the markup above
is native elements and native ARIA, and everything a keyboard or a screen reader does with it
comes from the platform. Nothing here manages focus, and nothing here adds a role you did not
author. So the accessibility of this component is the accessibility of the markup — which is why
the markup is the part worth copying exactly.

## Before JavaScript runs

This primitive is CSS only. There is nothing to register and nothing to wait for.
