# Field

Combine labels, controls, and help text to compose accessible form fields and grouped inputs.

Source: https://webjs.dev/ui/docs/components/field

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { buttonClass } from '#components/ui/button.ts';
import { checkboxClass } from '#components/ui/checkbox.ts';
import {
  fieldSetClass, fieldLegendClass, fieldGroupClass, fieldClass, fieldLabelClass,
  fieldDescriptionClass, fieldSeparatorClass,
} from '#components/ui/field.ts';
import { inputClass } from '#components/ui/input.ts';
import { selectTriggerClass } from '#components/ui/select.ts';
import { textareaClass } from '#components/ui/textarea.ts';

const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
const years = ['2024', '2025', '2026', '2027', '2028', '2029'];

export default function FieldDemo() {
  return html`
    <div class="w-full max-w-md">
      <form>
        <div data-slot="field-group" class=${fieldGroupClass()}>
          <fieldset data-slot="field-set" class=${fieldSetClass()}>
            <legend data-slot="field-legend" data-variant="legend" class=${fieldLegendClass()}>Payment Method</legend>
            <p data-slot="field-description" class=${fieldDescriptionClass()}>
              All transactions are secure and encrypted
            </p>
            <div data-slot="field-group" class=${fieldGroupClass()}>
              <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                <label data-slot="field-label" for="checkout-7j9-card-name-43j" class=${fieldLabelClass()}>
                  Name on Card
                </label>
                <input data-slot="input" id="checkout-7j9-card-name-43j" placeholder="Evil Rabbit" required class=${inputClass()}>
              </div>
              <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                <label data-slot="field-label" for="checkout-7j9-card-number-uw1" class=${fieldLabelClass()}>
                  Card Number
                </label>
                <input data-slot="input" id="checkout-7j9-card-number-uw1" placeholder="1234 5678 9012 3456" required class=${inputClass()}>
                <p data-slot="field-description" class=${fieldDescriptionClass()}>
                  Enter your 16-digit card number
                </p>
              </div>
              <div class="grid grid-cols-3 gap-4">
                <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                  <label data-slot="field-label" for="checkout-exp-month-ts6" class=${fieldLabelClass()}>
                    Month
                  </label>
                  <ui-select placeholder="MM">
                    <select id="checkout-exp-month-ts6" class=${selectTriggerClass()}>
                      <option value="" disabled selected hidden>MM</option>
                      ${months.map((m) => html`<option value=${m}>${m}</option>`)}
                    </select>
                  </ui-select>
                </div>
                <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                  <label data-slot="field-label" for="checkout-7j9-exp-year-f59" class=${fieldLabelClass()}>
                    Year
                  </label>
                  <ui-select placeholder="YYYY">
                    <select id="checkout-7j9-exp-year-f59" class=${selectTriggerClass()}>
                      <option value="" disabled selected hidden>YYYY</option>
                      ${years.map((y) => html`<option value=${y}>${y}</option>`)}
                    </select>
                  </ui-select>
                </div>
                <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                  <label data-slot="field-label" for="checkout-7j9-cvv" class=${fieldLabelClass()}>CVV</label>
                  <input data-slot="input" id="checkout-7j9-cvv" placeholder="123" required class=${inputClass()}>
                </div>
              </div>
            </div>
          </fieldset>
          <div data-slot="field-separator" data-content="false" class=${fieldSeparatorClass()}></div>
          <fieldset data-slot="field-set" class=${fieldSetClass()}>
            <legend data-slot="field-legend" data-variant="legend" class=${fieldLegendClass()}>Billing Address</legend>
            <p data-slot="field-description" class=${fieldDescriptionClass()}>
              The billing address associated with your payment method
            </p>
            <div data-slot="field-group" class=${fieldGroupClass()}>
              <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
                <input type="checkbox" data-slot="checkbox" id="checkout-7j9-same-as-shipping-wgm" checked class=${checkboxClass()}>
                <label data-slot="field-label" for="checkout-7j9-same-as-shipping-wgm" class=${cn(fieldLabelClass(), 'font-normal')}>
                  Same as shipping address
                </label>
              </div>
            </div>
          </fieldset>
          <fieldset data-slot="field-set" class=${fieldSetClass()}>
            <div data-slot="field-group" class=${fieldGroupClass()}>
              <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                <label data-slot="field-label" for="checkout-7j9-optional-comments" class=${fieldLabelClass()}>
                  Comments
                </label>
                <textarea data-slot="textarea" id="checkout-7j9-optional-comments" placeholder="Add any additional comments" class=${cn(textareaClass(), 'resize-none')}></textarea>
              </div>
            </div>
          </fieldset>
          <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
            <button type="submit" data-slot="button" data-variant="default" data-size="default" class=${buttonClass()}>Submit</button>
            <button type="button" data-slot="button" data-variant="outline" data-size="default" class=${buttonClass({ variant: 'outline' })}>
              Cancel
            </button>
          </div>
        </div>
      </form>
    </div>
  `;
}
```

## Installation

```bash
npx @webjsdev/ui add field
```

### Copy and paste the following code into your project.

````ts title="components/ui/field.ts"
/**
 * Field: the layout system for a form, a label, a control, its helper text,
 * and its error message, plus the fieldset, legend, and group that hold many
 * fields. Tier-1 class helpers; compose with the native elements (`<fieldset>`,
 * `<legend>`, `<label>`, `<p>`) and the kit's control helpers
 * (`inputClass()`, `textareaClass()`, `checkboxClass()`, and the rest).
 *
 * shadcn parity:
 *   FieldSet                             → fieldSetClass()
 *   FieldLegend (variant: legend | label) → fieldLegendClass({ variant })
 *   FieldGroup                           → fieldGroupClass()
 *   Field (orientation: vertical | horizontal | responsive) → fieldClass({ orientation })
 *   FieldContent                         → fieldContentClass()
 *   FieldLabel                           → fieldLabelClass()
 *   FieldTitle                           → fieldTitleClass()
 *   FieldDescription                     → fieldDescriptionClass()
 *   FieldError                           → fieldErrorClass()
 *   FieldSeparator                       → fieldSeparatorClass() + fieldSeparatorContentClass()
 *
 * Set the shadcn data attributes on the same elements, because the sibling and
 * group rules key on them: `data-slot="field"` + `data-orientation` on the
 * field, `data-slot="field-label"` on the label, `data-slot="field-content"`
 * on the content wrapper, `data-variant` on the legend, and
 * `data-slot="field-group"` on the group (the `responsive` orientation reads
 * the group's container width).
 *
 * Invalid state: put `data-invalid="true"` on the field, which turns the
 * field's text destructive (`data-[invalid=true]:text-destructive`), and
 * `aria-invalid="true"` on the control, which the control helpers style.
 * Disabled state: `data-disabled="true"` on the field fades its label.
 *
 * Not the same as the `fieldClass()` / `fieldLabelClass()` in the `cn()`
 * helper module (`lib/utils/cn.ts`), which are the older single-field rhythm
 * helpers (`grid gap-2`). Both keep working. Import each from its own module,
 * and alias one (`import { fieldClass as fieldStackClass } from ...`) if a file
 * needs both.
 *
 * Design tokens used: --destructive, --muted-foreground, --primary,
 * --background, --border.
 *
 * A11y (required for accessible output):
 *   Every control has a real `<label for>` (`fieldLabelClass()`), never a
 *   placeholder alone. A field carries `role="group"` (as shadcn's does) only
 *   when it holds more than one control; a single-control field needs no role.
 *   Wire the helper and error text to the control with `aria-describedby`,
 *   listing the description id and, when invalid, the error id
 *   (`aria-describedby="email-desc email-error"`). Point it only at ids that
 *   EXIST on the page, so render the error element only when there is an error.
 *   On a server validation error, re-render the form with the typed values
 *   kept (`value=${values.email}`), `data-invalid="true"` on the field,
 *   `aria-invalid="true"` on the control, and the message in
 *   `fieldErrorClass()` with `role="alert"`, so the user fixes the one field
 *   instead of retyping the form. Move focus to the first invalid control.
 *   Group related controls (a radio set, a checkbox list) in a `<fieldset>`
 *   with a `<legend>` (`fieldSetClass()` / `fieldLegendClass()`), which names
 *   the group. A `fieldTitleClass()` element is NOT a label: use it for the
 *   title inside a choice card whose `<label>` wraps the whole card.
 *   A decorative separator gets `role="none"`; its text (`or`) stays readable.
 *
 * @example
 * ```html
 * <form method="post" class="w-full max-w-md">
 *   <fieldset class=${fieldSetClass()}>
 *     <legend class=${fieldLegendClass()} data-variant="legend">Profile</legend>
 *     <p class=${fieldDescriptionClass()}>This is how others see you.</p>
 *     <div class=${fieldGroupClass()} data-slot="field-group">
 *       <div class=${fieldClass()} data-slot="field" data-orientation="vertical">
 *         <label class=${fieldLabelClass()} data-slot="field-label" for="name">Name</label>
 *         <input class=${inputClass()} id="name" name="name" value="Ada" aria-describedby="name-desc">
 *         <p class=${fieldDescriptionClass()} id="name-desc">Shown on your public page.</p>
 *       </div>
 *       <div class=${fieldClass()} data-slot="field" data-orientation="vertical" data-invalid="true">
 *         <label class=${fieldLabelClass()} data-slot="field-label" for="email">Email</label>
 *         <input class=${inputClass()} id="email" name="email" type="email" value="ada@" aria-invalid="true" aria-describedby="email-error">
 *         <div class=${fieldErrorClass()} id="email-error" role="alert">Enter a valid email address.</div>
 *       </div>
 *       <div class=${fieldSeparatorClass()} role="none"><span class=${fieldSeparatorContentClass()}>Notifications</span></div>
 *       <div class=${fieldClass({ orientation: 'horizontal' })} data-slot="field" data-orientation="horizontal">
 *         <input class=${checkboxClass()} data-slot="checkbox" type="checkbox" id="digest" name="digest">
 *         <label class=${fieldLabelClass()} data-slot="field-label" for="digest">Send me a weekly digest</label>
 *       </div>
 *     </div>
 *   </fieldset>
 * </form>
 * ```
 */

export type FieldLegendVariant = 'legend' | 'label';
export type FieldOrientation = 'vertical' | 'horizontal' | 'responsive';

const LEGEND_VARIANTS = {
  legend: 'text-base',
  label: 'text-sm',
} as const;

// shadcn's `*:w-full` widens a field's control because the control is the
// field's child. A `<ui-select>` host is `display: contents` and its trigger
// (or, before it upgrades, the native select) sits two levels down, so the
// same width reaches through the host to it.
const ORIENTATIONS = {
  vertical: '[&>*]:w-full flex-col *:w-full [&>.sr-only]:w-auto [&>ui-select_:is(select,[data-slot=select-trigger])]:w-full',
  horizontal: '[&>[data-slot=field-label]]:flex-auto has-[>[data-slot=field-content]]:[&>[type=checkbox],[type=radio]]:mt-px flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px',
  responsive: '[&>*]:w-full @md/field-group:[&>*]:w-auto @md/field-group:[&>[data-slot=field-label]]:flex-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[type=checkbox],[type=radio]]:mt-px flex-col *:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px [&>ui-select_:is(select,[data-slot=select-trigger])]:w-full @md/field-group:[&>ui-select_:is(select,[data-slot=select-trigger])]:w-auto',
} as const;

/** Field set: a native `<fieldset>` holding a legend and a group of fields. */
export const fieldSetClass = (): string =>
  'gap-6 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3 flex flex-col';

/**
 * Field legend: the `<legend>` naming a field set. `legend` is section-sized,
 * `label` matches a field label (for a radio or checkbox set). Set
 * `data-variant="<variant>"` on the same element so a following description
 * tightens its spacing.
 */
export function fieldLegendClass(opts: { variant?: FieldLegendVariant } = {}): string {
  return 'mb-3 font-medium ' + LEGEND_VARIANTS[opts.variant ?? 'legend'];
}

/** Field group: stacks fields, and is the container `responsive` fields measure. */
export const fieldGroupClass = (): string =>
  'gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4 group/field-group @container/field-group flex w-full flex-col';

/**
 * Field: one label + control + text unit. `vertical` stacks them, `horizontal`
 * puts the control beside the label (checkbox, switch), and `responsive` stacks
 * on a narrow group and goes side by side from the group's `md` width.
 */
export function fieldClass(opts: { orientation?: FieldOrientation } = {}): string {
  return (
    'gap-3 data-[invalid=true]:text-destructive group/field flex w-full ' +
    ORIENTATIONS[opts.orientation ?? 'vertical']
  );
}

/** Field content: wraps a label and description beside a horizontal control. */
export const fieldContentClass = (): string =>
  'gap-1.5 group/field-content flex flex-1 flex-col leading-snug';

/** Field label: the `<label for>` of the control. Fades when the field is data-disabled. */
export const fieldLabelClass = (): string =>
  'gap-2 text-sm leading-none font-medium group-data-[disabled=true]:opacity-50 peer-disabled:opacity-50 items-center leading-snug select-none group-data-[disabled=true]/field:opacity-50 peer-disabled:cursor-not-allowed has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4 has-checked:border-primary has-checked:bg-primary/5 dark:has-checked:bg-primary/10 group/field-label peer/field-label flex w-fit group-data-[disabled=true]:pointer-events-none';

/** Field title: label-styled text that is not a `<label>` (a choice card's heading). */
export const fieldTitleClass = (): string =>
  'gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50 flex w-fit items-center';

/** Field description: the muted helper text under (or beside) the control. */
export const fieldDescriptionClass = (): string =>
  'text-sm text-muted-foreground group-has-[[data-orientation=horizontal]]/field:text-balance last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5 [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary leading-normal font-normal group-has-data-horizontal/field:text-balance';

/** Field error: the inline validation message. Give it an id the control's aria-describedby lists. */
export const fieldErrorClass = (): string => 'text-sm text-destructive font-normal';

/**
 * Field separator: a horizontal rule between fields, drawn by the element's own
 * `::before`, with optional centred text in a `fieldSeparatorContentClass()`
 * span.
 */
export const fieldSeparatorClass = (): string =>
  '-my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2 before:absolute before:inset-x-0 before:top-1/2 before:h-px before:bg-border relative';

/** Field separator content: the text on the separator line (`or`, a section name). */
export const fieldSeparatorContentClass = (): string =>
  'px-2 text-muted-foreground relative mx-auto block w-fit bg-background';
````

### Update the import paths to match your project setup.

## Usage

```ts
import {
  fieldClass,
  fieldContentClass,
  fieldDescriptionClass,
  fieldErrorClass,
  fieldGroupClass,
  fieldLabelClass,
  fieldLegendClass,
  fieldSeparatorClass,
  fieldSetClass,
  fieldTitleClass,
} from '#components/ui/field.ts';
```

```ts
<fieldset data-slot="field-set" class=${fieldSetClass()}>
  <legend data-slot="field-legend" data-variant="legend" class=${fieldLegendClass()}>Profile</legend>
  <p data-slot="field-description" class=${fieldDescriptionClass()}>This appears on invoices and emails.</p>
  <div data-slot="field-group" class=${fieldGroupClass()}>
    <div data-slot="field" data-orientation="vertical" class=${fieldClass()}>
      <label data-slot="field-label" for="name" class=${fieldLabelClass()}>Full name</label>
      <input data-slot="input" id="name" autocomplete="off" placeholder="Evil Rabbit" class=${inputClass()}>
      <p data-slot="field-description" class=${fieldDescriptionClass()}>This appears on invoices and emails.</p>
    </div>
    <div data-slot="field" data-orientation="vertical" data-invalid="true" class=${fieldClass()}>
      <label data-slot="field-label" for="username" class=${fieldLabelClass()}>Username</label>
      <input data-slot="input" id="username" autocomplete="off" aria-invalid="true" aria-describedby="username-error" class=${inputClass()}>
      <div data-slot="field-error" id="username-error" role="alert" class=${fieldErrorClass()}>Choose another username.</div>
    </div>
    <div data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
      <ui-switch input-id="newsletter"></ui-switch>
      <label data-slot="field-label" for="newsletter" class=${fieldLabelClass()}>Subscribe to the newsletter</label>
    </div>
  </div>
</fieldset>
```

## Composition

### Field

A single control with label, helper text, and validation.

```text
fieldClass()
├── fieldLabelClass()
├── inputClass() / textareaClass() / <ui-switch> / <ui-select>
├── fieldDescriptionClass()
└── fieldErrorClass()
```

### FieldGroup

Related fields in one group. Use `fieldSeparatorClass()` between sections when needed.

```text
fieldGroupClass()
├── fieldClass()
│   ├── fieldLabelClass()
│   ├── inputClass() / textareaClass() / <ui-switch> / <ui-select>
│   ├── fieldDescriptionClass()
│   └── fieldErrorClass()
├── fieldSeparatorClass()
└── fieldClass()
    ├── fieldLabelClass()
    └── inputClass() / textareaClass() / <ui-switch> / <ui-select>
```

### FieldSet

Semantic grouping with a legend and description, usually containing a field group.

```text
fieldSetClass()
├── fieldLegendClass()
├── fieldDescriptionClass()
└── fieldGroupClass()
    ├── fieldClass()
    │   ├── fieldLabelClass()
    │   ├── inputClass() / textareaClass() / <ui-switch> / <ui-select>
    │   ├── fieldDescriptionClass()
    │   └── fieldErrorClass()
    └── fieldClass()
        ├── fieldLabelClass()
        └── inputClass() / textareaClass() / <ui-switch> / <ui-select>
```

## Anatomy

The Field helpers are designed for composing accessible forms. A typical field is structured as follows:

```ts
<div data-slot="field" data-orientation="vertical" class=${fieldClass()}>
  <label data-slot="field-label" for="input-id" class=${fieldLabelClass()}>Label</label>
  <!-- Input, select, switch, etc. -->
  <p data-slot="field-description" class=${fieldDescriptionClass()}>Optional helper text.</p>
  <div data-slot="field-error" class=${fieldErrorClass()}>Validation message.</div>
</div>
```

- `fieldClass()` is the core wrapper for a single field.
- `fieldContentClass()` is a flex column that groups label and description. Not required if you have no description.
- Wrap related fields with `fieldGroupClass()`, and use a `<fieldset>` with `fieldSetClass()` and a `<legend>` with `fieldLegendClass()` for semantic grouping.

## Form

See the [Form](https://webjs.dev/ui/docs/forms) documentation for building forms with the Field helpers. In WebJs a form binds a server action with `<form action=${action}>`, works with JavaScript off, and re-renders with the action's field errors on a failed submission, so no form library is needed.

## Input

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import {
  fieldSetClass, fieldGroupClass, fieldClass, fieldLabelClass, fieldDescriptionClass,
} from '#components/ui/field.ts';
import { inputClass } from '#components/ui/input.ts';

export default function FieldInput() {
  return html`
    <fieldset data-slot="field-set" class=${cn(fieldSetClass(), 'w-full max-w-xs')}>
      <div data-slot="field-group" class=${fieldGroupClass()}>
        <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
          <label data-slot="field-label" for="username" class=${fieldLabelClass()}>Username</label>
          <input data-slot="input" id="username" type="text" placeholder="Max Leiter" class=${inputClass()}>
          <p data-slot="field-description" class=${fieldDescriptionClass()}>
            Choose a unique username for your account.
          </p>
        </div>
        <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
          <label data-slot="field-label" for="password" class=${fieldLabelClass()}>Password</label>
          <p data-slot="field-description" class=${fieldDescriptionClass()}>
            Must be at least 8 characters long.
          </p>
          <input data-slot="input" id="password" type="password" placeholder="••••••••" class=${inputClass()}>
        </div>
      </div>
    </fieldset>
  `;
}
```

## Textarea

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import {
  fieldSetClass, fieldGroupClass, fieldClass, fieldLabelClass, fieldDescriptionClass,
} from '#components/ui/field.ts';
import { textareaClass } from '#components/ui/textarea.ts';

export default function FieldTextarea() {
  return html`
    <fieldset data-slot="field-set" class=${cn(fieldSetClass(), 'w-full max-w-xs')}>
      <div data-slot="field-group" class=${fieldGroupClass()}>
        <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
          <label data-slot="field-label" for="feedback" class=${fieldLabelClass()}>Feedback</label>
          <textarea data-slot="textarea" id="feedback" placeholder="Your feedback helps us improve..." rows="4" class=${textareaClass()}></textarea>
          <p data-slot="field-description" class=${fieldDescriptionClass()}>
            Share your thoughts about our service.
          </p>
        </div>
      </div>
    </fieldset>
  `;
}
```

## Select

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { fieldClass, fieldLabelClass, fieldDescriptionClass } from '#components/ui/field.ts';
import { selectTriggerClass } from '#components/ui/select.ts';

export default function FieldSelect() {
  return html`
    <div role="group" data-slot="field" data-orientation="vertical" class=${cn(fieldClass(), 'w-full max-w-xs')}>
      <label data-slot="field-label" for="field-select-department" class=${fieldLabelClass()}>Department</label>
      <ui-select placeholder="Choose department">
        <select id="field-select-department" class=${selectTriggerClass()}>
          <option value="" disabled selected hidden>Choose department</option>
          <option value="engineering">Engineering</option>
          <option value="design">Design</option>
          <option value="marketing">Marketing</option>
          <option value="sales">Sales</option>
          <option value="support">Customer Support</option>
          <option value="hr">Human Resources</option>
          <option value="finance">Finance</option>
          <option value="operations">Operations</option>
        </select>
      </ui-select>
      <p data-slot="field-description" class=${fieldDescriptionClass()}>
        Select your department or area of work.
      </p>
    </div>
  `;
}
```

## Slider

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { fieldClass, fieldTitleClass, fieldDescriptionClass } from '#components/ui/field.ts';
import { sliderClass } from '#components/ui/slider.ts';

// Two range inputs make a range; the description shows the settled values.
export default function FieldSlider() {
  const value = [200, 800];

  return html`
    <div role="group" data-slot="field" data-orientation="vertical" class=${cn(fieldClass(), 'w-full max-w-xs')}>
      <div data-slot="field-label" class=${fieldTitleClass()}>Price Range</div>
      <p data-slot="field-description" class=${fieldDescriptionClass()}>
        Set your budget range ($<span class="font-medium tabular-nums">${value[0]}</span> -
        <span class="font-medium tabular-nums">${value[1]}</span>).
      </p>
      <ui-slider class="mt-2 w-full">
        <input type="range" min="0" max="1000" step="10" value=${value[0]} aria-label="Minimum price" class=${sliderClass()}>
        <input type="range" min="0" max="1000" step="10" value=${value[1]} aria-label="Maximum price" class=${sliderClass()}>
      </ui-slider>
    </div>
  `;
}
```

## Fieldset

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import {
  fieldSetClass, fieldLegendClass, fieldGroupClass, fieldClass, fieldLabelClass,
  fieldDescriptionClass,
} from '#components/ui/field.ts';
import { inputClass } from '#components/ui/input.ts';

export default function FieldFieldset() {
  return html`
    <fieldset data-slot="field-set" class=${cn(fieldSetClass(), 'w-full max-w-sm')}>
      <legend data-slot="field-legend" data-variant="legend" class=${fieldLegendClass()}>Address Information</legend>
      <p data-slot="field-description" class=${fieldDescriptionClass()}>
        We need your address to deliver your order.
      </p>
      <div data-slot="field-group" class=${fieldGroupClass()}>
        <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
          <label data-slot="field-label" for="street" class=${fieldLabelClass()}>Street Address</label>
          <input data-slot="input" id="street" type="text" placeholder="123 Main St" class=${inputClass()}>
        </div>
        <div class="grid grid-cols-2 gap-4">
          <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
            <label data-slot="field-label" for="city" class=${fieldLabelClass()}>City</label>
            <input data-slot="input" id="city" type="text" placeholder="New York" class=${inputClass()}>
          </div>
          <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
            <label data-slot="field-label" for="zip" class=${fieldLabelClass()}>Postal Code</label>
            <input data-slot="input" id="zip" type="text" placeholder="90502" class=${inputClass()}>
          </div>
        </div>
      </div>
    </fieldset>
  `;
}
```

## Checkbox

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { checkboxClass } from '#components/ui/checkbox.ts';
import {
  fieldSetClass, fieldLegendClass, fieldGroupClass, fieldClass, fieldContentClass,
  fieldLabelClass, fieldDescriptionClass, fieldSeparatorClass,
} from '#components/ui/field.ts';

const items = [
  { id: 'finder-pref-9k2-hard-disks-ljj', label: 'Hard disks' },
  { id: 'finder-pref-9k2-external-disks-1yg', label: 'External disks' },
  { id: 'finder-pref-9k2-cds-dvds-fzt', label: 'CDs, DVDs, and iPods' },
  { id: 'finder-pref-9k2-connected-servers-6l2', label: 'Connected servers' },
];

export default function FieldCheckbox() {
  return html`
    <div data-slot="field-group" class=${cn(fieldGroupClass(), 'w-full max-w-xs')}>
      <fieldset data-slot="field-set" class=${fieldSetClass()}>
        <legend data-slot="field-legend" data-variant="label" class=${fieldLegendClass({ variant: 'label' })}>
          Show these items on the desktop
        </legend>
        <p data-slot="field-description" class=${fieldDescriptionClass()}>
          Select the items you want to show on the desktop.
        </p>
        <div data-slot="field-group" class=${cn(fieldGroupClass(), 'gap-3')}>
          ${items.map((item) => html`
            <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
              <input type="checkbox" data-slot="checkbox" id=${item.id} class=${checkboxClass()}>
              <label data-slot="field-label" for=${item.id} class=${cn(fieldLabelClass(), 'font-normal')}>
                ${item.label}
              </label>
            </div>
          `)}
        </div>
      </fieldset>
      <div data-slot="field-separator" data-content="false" class=${fieldSeparatorClass()}></div>
      <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
        <input type="checkbox" data-slot="checkbox" id="finder-pref-9k2-sync-folders-nep" checked class=${checkboxClass()}>
        <div data-slot="field-content" class=${fieldContentClass()}>
          <label data-slot="field-label" for="finder-pref-9k2-sync-folders-nep" class=${fieldLabelClass()}>
            Sync Desktop &amp; Documents folders
          </label>
          <p data-slot="field-description" class=${fieldDescriptionClass()}>
            Your Desktop &amp; Documents folders are being synced with iCloud Drive.
            You can access them from other devices.
          </p>
        </div>
      </div>
    </div>
  `;
}
```

## Radio

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import {
  fieldSetClass, fieldLegendClass, fieldClass, fieldLabelClass, fieldDescriptionClass,
} from '#components/ui/field.ts';
import { radioGroupClass, radioClass } from '#components/ui/radio-group.ts';

const plans = [
  { value: 'monthly', id: 'plan-monthly', label: 'Monthly ($9.99/month)' },
  { value: 'yearly', id: 'plan-yearly', label: 'Yearly ($99.99/year)' },
  { value: 'lifetime', id: 'plan-lifetime', label: 'Lifetime ($299.99)' },
];

export default function FieldRadio() {
  const defaultValue = 'monthly';

  return html`
    <fieldset data-slot="field-set" class=${cn(fieldSetClass(), 'w-full max-w-xs')}>
      <legend data-slot="field-legend" data-variant="label" class=${fieldLegendClass({ variant: 'label' })}>Subscription Plan</legend>
      <p data-slot="field-description" class=${fieldDescriptionClass()}>
        Yearly and lifetime plans offer significant savings.
      </p>
      <div role="radiogroup" data-slot="radio-group" class=${radioGroupClass()}>
        ${plans.map((plan) => html`
          <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
            <input type="radio" data-slot="radio" name="field-radio-plan" value=${plan.value} id=${plan.id} ?checked=${plan.value === defaultValue} class=${radioClass()}>
            <label data-slot="field-label" for=${plan.id} class=${cn(fieldLabelClass(), 'font-normal')}>
              ${plan.label}
            </label>
          </div>
        `)}
      </div>
    </fieldset>
  `;
}
```

## Switch

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { fieldClass, fieldLabelClass } from '#components/ui/field.ts';

export default function FieldSwitch() {
  return html`
    <div role="group" data-slot="field" data-orientation="horizontal" class=${cn(fieldClass({ orientation: 'horizontal' }), 'w-fit')}>
      <label data-slot="field-label" for="2fa" class=${fieldLabelClass()}>Multi-factor authentication</label>
      <ui-switch input-id="2fa"></ui-switch>
    </div>
  `;
}
```

## Choice Card

Wrap a field inside a `<label>` with `fieldLabelClass()` to create selectable field groups. This works with radio inputs, checkboxes and `<ui-switch>`.

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import {
  fieldSetClass, fieldLegendClass, fieldGroupClass, fieldClass, fieldContentClass,
  fieldLabelClass, fieldTitleClass, fieldDescriptionClass,
} from '#components/ui/field.ts';
import { radioGroupClass, radioClass } from '#components/ui/radio-group.ts';

const options = [
  { value: 'kubernetes', id: 'kubernetes-r2h', title: 'Kubernetes', description: 'Run GPU workloads on a K8s cluster.' },
  { value: 'vm', id: 'vm-z4k', title: 'Virtual Machine', description: 'Access a cluster to run GPU workloads.' },
];

// The whole card is the <label>, so a click anywhere on it picks the radio.
export default function FieldChoiceCard() {
  const defaultValue = 'kubernetes';

  return html`
    <div data-slot="field-group" class=${cn(fieldGroupClass(), 'w-full max-w-xs')}>
      <fieldset data-slot="field-set" class=${fieldSetClass()}>
        <legend data-slot="field-legend" data-variant="label" class=${fieldLegendClass({ variant: 'label' })}>Compute Environment</legend>
        <p data-slot="field-description" class=${fieldDescriptionClass()}>
          Select the compute environment for your cluster.
        </p>
        <div role="radiogroup" data-slot="radio-group" class=${radioGroupClass()}>
          ${options.map((option) => html`
            <label data-slot="field-label" for=${option.id} class=${fieldLabelClass()}>
              <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
                <div data-slot="field-content" class=${fieldContentClass()}>
                  <div data-slot="field-label" class=${fieldTitleClass()}>${option.title}</div>
                  <p data-slot="field-description" class=${fieldDescriptionClass()}>${option.description}</p>
                </div>
                <input type="radio" data-slot="radio" name="field-choice-card" value=${option.value} id=${option.id} ?checked=${option.value === defaultValue} class=${radioClass()}>
              </div>
            </label>
          `)}
        </div>
      </fieldset>
    </div>
  `;
}
```

## Field Group

Stack fields with `fieldGroupClass()`. Add a `fieldSeparatorClass()` element to divide them.

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { checkboxClass } from '#components/ui/checkbox.ts';
import {
  fieldSetClass, fieldGroupClass, fieldClass, fieldLabelClass, fieldDescriptionClass,
  fieldSeparatorClass,
} from '#components/ui/field.ts';

export default function FieldGroupExample() {
  return html`
    <div data-slot="field-group" class=${cn(fieldGroupClass(), 'w-full max-w-xs')}>
      <fieldset data-slot="field-set" class=${fieldSetClass()}>
        <label data-slot="field-label" class=${fieldLabelClass()}>Responses</label>
        <p data-slot="field-description" class=${fieldDescriptionClass()}>
          Get notified when ChatGPT responds to requests that take time, like
          research or image generation.
        </p>
        <div data-slot="checkbox-group" class=${fieldGroupClass()}>
          <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
            <input type="checkbox" data-slot="checkbox" id="push" checked disabled class=${checkboxClass()}>
            <label data-slot="field-label" for="push" class=${cn(fieldLabelClass(), 'font-normal')}>
              Push notifications
            </label>
          </div>
        </div>
      </fieldset>
      <div data-slot="field-separator" data-content="false" class=${fieldSeparatorClass()}></div>
      <fieldset data-slot="field-set" class=${fieldSetClass()}>
        <label data-slot="field-label" class=${fieldLabelClass()}>Tasks</label>
        <p data-slot="field-description" class=${fieldDescriptionClass()}>
          Get notified when tasks you&apos;ve created have updates.
          <a href="#">Manage tasks</a>
        </p>
        <div data-slot="checkbox-group" class=${fieldGroupClass()}>
          <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
            <input type="checkbox" data-slot="checkbox" id="push-tasks" class=${checkboxClass()}>
            <label data-slot="field-label" for="push-tasks" class=${cn(fieldLabelClass(), 'font-normal')}>
              Push notifications
            </label>
          </div>
          <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
            <input type="checkbox" data-slot="checkbox" id="email-tasks" class=${checkboxClass()}>
            <label data-slot="field-label" for="email-tasks" class=${cn(fieldLabelClass(), 'font-normal')}>
              Email notifications
            </label>
          </div>
        </div>
      </fieldset>
    </div>
  `;
}
```

## RTL

To enable RTL support, see the [RTL configuration guide](https://webjs.dev/ui/docs/rtl).

```ts
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { buttonClass } from '#components/ui/button.ts';
import { checkboxClass } from '#components/ui/checkbox.ts';
import {
  fieldSetClass, fieldLegendClass, fieldGroupClass, fieldClass, fieldLabelClass,
  fieldDescriptionClass, fieldSeparatorClass,
} from '#components/ui/field.ts';
import { inputClass } from '#components/ui/input.ts';
import { selectTriggerClass } from '#components/ui/select.ts';
import { textareaClass } from '#components/ui/textarea.ts';

const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
const years = ['2024', '2025', '2026', '2027', '2028', '2029'];

const translations = {
  en: {
    dir: 'ltr',
    values: {
      paymentMethod: 'Payment Method',
      secureTransactions: 'All transactions are secure and encrypted',
      nameOnCard: 'Name on Card',
      cardNumber: 'Card Number',
      cardNumberDescription: 'Enter your 16-digit card number',
      month: 'Month',
      year: 'Year',
      cvv: 'CVV',
      monthPlaceholder: 'MM',
      months: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
      billingAddress: 'Billing Address',
      billingAddressDescription: 'The billing address associated with your payment method',
      sameAsShipping: 'Same as shipping address',
      comments: 'Comments',
      commentsPlaceholder: 'Add any additional comments',
      submit: 'Submit',
      cancel: 'Cancel',
    },
  },
  ar: {
    dir: 'rtl',
    values: {
      paymentMethod: 'طريقة الدفع',
      secureTransactions: 'جميع المعاملات آمنة ومشفرة',
      nameOnCard: 'الاسم على البطاقة',
      cardNumber: 'رقم البطاقة',
      cardNumberDescription: 'أدخل رقم البطاقة المكون من 16 رقمًا',
      month: 'الشهر',
      year: 'السنة',
      cvv: 'CVV',
      monthPlaceholder: 'ش.ش',
      months: ['٠١', '٠٢', '٠٣', '٠٤', '٠٥', '٠٦', '٠٧', '٠٨', '٠٩', '١٠', '١١', '١٢'],
      billingAddress: 'عنوان الفوترة',
      billingAddressDescription: 'عنوان الفوترة المرتبط بطريقة الدفع الخاصة بك',
      sameAsShipping: 'نفس عنوان الشحن',
      comments: 'تعليقات',
      commentsPlaceholder: 'أضف أي تعليقات إضافية',
      submit: 'إرسال',
      cancel: 'إلغاء',
    },
  },
  he: {
    dir: 'rtl',
    values: {
      paymentMethod: 'אמצעי תשלום',
      secureTransactions: 'כל העסקאות מאובטחות ומוצפנות',
      nameOnCard: 'שם על הכרטיס',
      cardNumber: 'מספר כרטיס',
      cardNumberDescription: 'הזן את מספר הכרטיס בן 16 הספרות שלך',
      month: 'חודש',
      year: 'שנה',
      cvv: 'CVV',
      monthPlaceholder: 'MM',
      months: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
      billingAddress: 'כתובת חיוב',
      billingAddressDescription: 'כתובת החיוב המשויכת לאמצעי התשלום שלך',
      sameAsShipping: 'זהה לכתובת המשלוח',
      comments: 'הערות',
      commentsPlaceholder: 'הוסף הערות נוספות',
      submit: 'שלח',
      cancel: 'בטל',
    },
  },
};

export default function FieldRtl() {
  const lang = 'ar';
  const { dir, values: t } = translations[lang];

  return html`
    <div class="w-full max-w-md py-6" dir=${dir} lang=${lang}>
      <form>
        <div data-slot="field-group" class=${fieldGroupClass()}>
          <fieldset data-slot="field-set" class=${fieldSetClass()}>
            <legend data-slot="field-legend" data-variant="legend" class=${fieldLegendClass()}>${t.paymentMethod}</legend>
            <p data-slot="field-description" class=${fieldDescriptionClass()}>${t.secureTransactions}</p>
            <div data-slot="field-group" class=${fieldGroupClass()}>
              <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                <label data-slot="field-label" for="checkout-7j9-card-name-43j-rtl" class=${fieldLabelClass()}>
                  ${t.nameOnCard}
                </label>
                <input data-slot="input" id="checkout-7j9-card-name-43j-rtl" placeholder="Evil Rabbit" required class=${inputClass()}>
              </div>
              <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                <label data-slot="field-label" for="checkout-7j9-card-number-uw1-rtl" class=${fieldLabelClass()}>
                  ${t.cardNumber}
                </label>
                <input data-slot="input" id="checkout-7j9-card-number-uw1-rtl" placeholder="1234 5678 9012 3456" required class=${inputClass()}>
                <p data-slot="field-description" class=${fieldDescriptionClass()}>${t.cardNumberDescription}</p>
              </div>
              <div class="grid grid-cols-3 gap-4">
                <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                  <label data-slot="field-label" for="checkout-exp-month-ts6-rtl" class=${fieldLabelClass()}>
                    ${t.month}
                  </label>
                  <ui-select placeholder=${t.monthPlaceholder}>
                    <select id="checkout-exp-month-ts6-rtl" class=${selectTriggerClass()}>
                      <option value="" disabled selected hidden>${t.monthPlaceholder}</option>
                      ${months.map((m, i) => html`<option value=${m}>${t.months[i]}</option>`)}
                    </select>
                  </ui-select>
                </div>
                <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                  <label data-slot="field-label" for="checkout-7j9-exp-year-f59-rtl" class=${fieldLabelClass()}>
                    ${t.year}
                  </label>
                  <ui-select placeholder="YYYY">
                    <select id="checkout-7j9-exp-year-f59-rtl" class=${selectTriggerClass()}>
                      <option value="" disabled selected hidden>YYYY</option>
                      ${years.map((y) => html`<option value=${y}>${y}</option>`)}
                    </select>
                  </ui-select>
                </div>
                <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                  <label data-slot="field-label" for="checkout-7j9-cvv-rtl" class=${fieldLabelClass()}>${t.cvv}</label>
                  <input data-slot="input" id="checkout-7j9-cvv-rtl" placeholder="123" required class=${inputClass()}>
                </div>
              </div>
            </div>
          </fieldset>
          <div data-slot="field-separator" data-content="false" class=${fieldSeparatorClass()}></div>
          <fieldset data-slot="field-set" class=${fieldSetClass()}>
            <legend data-slot="field-legend" data-variant="legend" class=${fieldLegendClass()}>${t.billingAddress}</legend>
            <p data-slot="field-description" class=${fieldDescriptionClass()}>${t.billingAddressDescription}</p>
            <div data-slot="field-group" class=${fieldGroupClass()}>
              <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
                <input type="checkbox" data-slot="checkbox" id="checkout-7j9-same-as-shipping-wgm-rtl" checked class=${checkboxClass()}>
                <label data-slot="field-label" for="checkout-7j9-same-as-shipping-wgm-rtl" class=${cn(fieldLabelClass(), 'font-normal')}>
                  ${t.sameAsShipping}
                </label>
              </div>
            </div>
          </fieldset>
          <fieldset data-slot="field-set" class=${fieldSetClass()}>
            <div data-slot="field-group" class=${fieldGroupClass()}>
              <div role="group" data-slot="field" data-orientation="vertical" class=${fieldClass()}>
                <label data-slot="field-label" for="checkout-7j9-optional-comments-rtl" class=${fieldLabelClass()}>
                  ${t.comments}
                </label>
                <textarea data-slot="textarea" id="checkout-7j9-optional-comments-rtl" placeholder=${t.commentsPlaceholder} class=${cn(textareaClass(), 'resize-none')}></textarea>
              </div>
            </div>
          </fieldset>
          <div role="group" data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
            <button type="submit" data-slot="button" data-variant="default" data-size="default" class=${buttonClass()}>${t.submit}</button>
            <button type="button" data-slot="button" data-variant="outline" data-size="default" class=${buttonClass({ variant: 'outline' })}>
              ${t.cancel}
            </button>
          </div>
        </div>
      </form>
    </div>
  `;
}
```

## Responsive Layout

- **Vertical fields:** Default orientation stacks label, control, and helper text, ideal for mobile-first layouts.
- **Horizontal fields:** Pass `{ orientation: 'horizontal' }` to `fieldClass()` (with `data-orientation="horizontal"`) to align the label and control side-by-side. Pair with `fieldContentClass()` to keep descriptions aligned.
- **Responsive fields:** Pass `{ orientation: 'responsive' }` for automatic column layouts inside container-aware parents. `fieldGroupClass()` already carries `@container/field-group`, so a responsive field switches orientation at the group's `md` width.

```ts
import { html } from '@webjsdev/core';
import { buttonClass } from '#components/ui/button.ts';
import {
  fieldSetClass, fieldLegendClass, fieldGroupClass, fieldClass, fieldContentClass,
  fieldLabelClass, fieldDescriptionClass,
} from '#components/ui/field.ts';
import { inputClass } from '#components/ui/input.ts';

export default function FieldResponsive() {
  return html`
    <div class="w-full max-w-lg">
      <form>
        <fieldset data-slot="field-set" class=${fieldSetClass()}>
          <legend data-slot="field-legend" data-variant="legend" class=${fieldLegendClass()}>Profile</legend>
          <p data-slot="field-description" class=${fieldDescriptionClass()}>Fill in your profile information.</p>
          <div data-slot="field-group" class=${fieldGroupClass()}>
            <div role="group" data-slot="field" data-orientation="responsive" class=${fieldClass({ orientation: 'responsive' })}>
              <div data-slot="field-content" class=${fieldContentClass()}>
                <label data-slot="field-label" for="name" class=${fieldLabelClass()}>Name</label>
                <p data-slot="field-description" class=${fieldDescriptionClass()}>
                  Provide your full name for identification
                </p>
              </div>
              <input data-slot="input" id="name" placeholder="Evil Rabbit" required class=${inputClass()}>
            </div>
            <div role="group" data-slot="field" data-orientation="responsive" class=${fieldClass({ orientation: 'responsive' })}>
              <button type="submit" data-slot="button" data-variant="default" data-size="default" class=${buttonClass()}>Submit</button>
              <button type="button" data-slot="button" data-variant="outline" data-size="default" class=${buttonClass({ variant: 'outline' })}>
                Cancel
              </button>
            </div>
          </div>
        </fieldset>
      </form>
    </div>
  `;
}
```

## Validation and Errors

- Add `data-invalid="true"` to the field to switch the entire block into an error state.
- Add `aria-invalid="true"` on the input itself for assistive technologies.
- Render the `fieldErrorClass()` element immediately after the control or inside the field content to keep error messages aligned with the field, and list its id in the control's `aria-describedby`.

```ts
<div data-slot="field" data-orientation="vertical" data-invalid="true" class=${fieldClass()}>
  <label data-slot="field-label" for="email" class=${fieldLabelClass()}>Email</label>
  <input data-slot="input" id="email" type="email" aria-invalid="true" aria-describedby="email-error" class=${inputClass()}>
  <div data-slot="field-error" id="email-error" role="alert" class=${fieldErrorClass()}>Enter a valid email address.</div>
</div>
```

## Accessibility

- A `<fieldset>` and `<legend>` keep related controls grouped for keyboard and assistive tech users.
- Add `role="group"` to a field that holds more than one control, so nested controls inherit labeling from the field's label and the set's legend when combined. A single-control field needs no role.
- Apply `fieldSeparatorClass()` sparingly to ensure screen readers encounter clear section boundaries.

## API Reference

Each helper returns the classes for one part. Put them on the native element named below, with the `data-slot` shown, since the group and sibling rules key on it.

### fieldSetClass

Classes for a semantic `<fieldset data-slot="field-set">` with spacing presets. Takes no options.

```ts
<fieldset data-slot="field-set" class=${fieldSetClass()}>
  <legend data-slot="field-legend" data-variant="legend" class=${fieldLegendClass()}>Delivery</legend>
  <div data-slot="field-group" class=${fieldGroupClass()}><!-- Fields --></div>
</fieldset>
```

### fieldLegendClass

Classes for the `<legend data-slot="field-legend">` of a field set. Switch to the `label` variant to align with label sizing, and set the same value on `data-variant`.

| Option | Type | Default |
| --- | --- | --- |
| `variant` | `"legend" \| "label"` | `"legend"` |

```ts
<legend data-slot="field-legend" data-variant="label" class=${fieldLegendClass({ variant: 'label' })}>Notification Preferences</legend>
```

The legend has two variants: `legend` and `label`. The `label` variant applies label sizing and alignment. Handy if you have a nested field set.

### fieldGroupClass

Classes for the `<div data-slot="field-group">` that stacks fields. It carries `@container/field-group`, the container that responsive fields measure. Takes no options.

```ts
<div data-slot="field-group" class=${fieldGroupClass()}>
  <div data-slot="field" class=${fieldClass()}>...</div>
  <div data-slot="field" class=${fieldClass()}>...</div>
</div>
```

### fieldClass

Classes for the core wrapper of a single field, a `<div data-slot="field">`. Provides orientation control, invalid state styling, and spacing. Set `data-orientation` to the same orientation, `data-invalid="true"` for the error state, and `data-disabled="true"` to fade the label.

| Option | Type | Default |
| --- | --- | --- |
| `orientation` | `"vertical" \| "horizontal" \| "responsive"` | `"vertical"` |

```ts
<div data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
  <label data-slot="field-label" for="remember" class=${fieldLabelClass()}>Remember me</label>
  <ui-switch input-id="remember"></ui-switch>
</div>
```

### fieldContentClass

Classes for a `<div data-slot="field-content">`, the flex column that groups label and descriptions when the label sits beside the control. Not required if you have no description. Takes no options.

```ts
<div data-slot="field" data-orientation="horizontal" class=${fieldClass({ orientation: 'horizontal' })}>
  <input type="checkbox" data-slot="checkbox" id="notifications" class=${checkboxClass()}>
  <div data-slot="field-content" class=${fieldContentClass()}>
    <label data-slot="field-label" for="notifications" class=${fieldLabelClass()}>Notifications</label>
    <p data-slot="field-description" class=${fieldDescriptionClass()}>Email, SMS, and push options.</p>
  </div>
</div>
```

### fieldLabelClass

Classes for the `<label data-slot="field-label">`, styled for both direct inputs and nested fields. Takes no options. A class helper styles any element.

```ts
<label data-slot="field-label" for="email" class=${fieldLabelClass()}>Email</label>
```

### fieldTitleClass

Classes for a title with label styling inside the field content, on an element that is not a `<label>` (a choice card's heading). Takes no options.

```ts
<div data-slot="field-content" class=${fieldContentClass()}>
  <div data-slot="field-label" class=${fieldTitleClass()}>Enable Touch ID</div>
  <p data-slot="field-description" class=${fieldDescriptionClass()}>Unlock your device faster.</p>
</div>
```

### fieldDescriptionClass

Classes for the helper text, a `<p data-slot="field-description">`, which balances long lines in horizontal layouts. Takes no options.

```ts
<p data-slot="field-description" class=${fieldDescriptionClass()}>We never share your email with anyone.</p>
```

### fieldSeparatorClass

Classes for a visual divider between sections inside a field group, a `<div data-slot="field-separator">` that draws its own line. Put optional inline text in a span with `fieldSeparatorContentClass()`, and set `data-content` to say whether it has any.

```ts
<div data-slot="field-separator" data-content="true" class=${fieldSeparatorClass()}>
  <span data-slot="field-separator-content" class=${fieldSeparatorContentClass()}>Or continue with</span>
</div>
```

### fieldErrorClass

Classes for the inline validation message, a `<div data-slot="field-error" role="alert">`. Takes no options. Render the messages your server action returned, and for several, a list inside the same element.

```ts
${actionData?.fieldErrors?.username
  ? html`<div data-slot="field-error" id="username-error" role="alert" class=${fieldErrorClass()}>${actionData.fieldErrors.username}</div>`
  : ''}
```

Give the error an id and list it in the control's `aria-describedby` only while it is rendered, so the description never points at an id that does not exist.
