# Field

Compose accessible form fields with labels, descriptions, and validation.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).





<ComponentPreview name="field-demo">
  <FieldDemo />
</ComponentPreview>

## Installation [#installation]

<Tabs defaultValue="cli">
  <TabsList>
    <TabsTrigger value="cli">
      CLI
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add https://shadcn-cssinjs.com/r/field.json
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Install the following dependencies:
      </Step>

      ```bash
      pnpm add @stylexjs/stylex
      ```

      <Step>
        Make sure [StyleX is configured](/docs/installation) and the design tokens are
        installed.
      </Step>

      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource name="field" title="field.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</Tabs>

## Usage [#usage]

```tsx
import {
  Field,
  FieldContent,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSeparator,
  FieldSet,
  FieldTitle,
} from "@/components/ui/field/field";
```

```tsx
<Field>
  <FieldLabel htmlFor="email">Email</FieldLabel>
  <Input id="email" type="email" />
  <FieldDescription>We never share your email.</FieldDescription>
</Field>
```

## Composition [#composition]

```text
FieldSet
├── FieldLegend
├── FieldDescription
└── FieldGroup
    └── Field
        ├── FieldLabel
        ├── (control)
        └── FieldDescription
```

## Examples [#examples]

### Input [#input]

<ComponentPreview name="field-input">
  <FieldInput />
</ComponentPreview>

### Textarea [#textarea]

<ComponentPreview name="field-textarea">
  <FieldTextarea />
</ComponentPreview>

### Select [#select]

<ComponentPreview name="field-select">
  <FieldSelect />
</ComponentPreview>

### Slider [#slider]

<ComponentPreview name="field-slider">
  <FieldSlider />
</ComponentPreview>

### Fieldset [#fieldset]

<ComponentPreview name="field-fieldset">
  <FieldFieldset />
</ComponentPreview>

### Checkbox [#checkbox]

<ComponentPreview name="field-checkbox">
  <FieldCheckbox />
</ComponentPreview>

### Radio [#radio]

<ComponentPreview name="field-radio">
  <FieldRadio />
</ComponentPreview>

### Switch [#switch]

<ComponentPreview name="field-switch">
  <FieldSwitch />
</ComponentPreview>

### Choice Card [#choice-card]

<ComponentPreview name="field-choice-card">
  <FieldChoiceCard />
</ComponentPreview>

### Field Group [#field-group]

<ComponentPreview name="field-group">
  <FieldGroupExample />
</ComponentPreview>

## Responsive Layout [#responsive-layout]

Use `orientation="responsive"` to stack the label and control on small screens
and place them side by side on larger screens.

<ComponentPreview name="field-responsive">
  <FieldResponsive />
</ComponentPreview>



## RTL [#rtl]

To enable right-to-left support, see the [RTL guide](/docs/rtl).

<ComponentPreview name="field-rtl" direction="rtl">
  <FieldRtl />
</ComponentPreview>

## API Reference [#api-reference]

### FieldSet [#fieldset-1]

Container that renders a semantic `fieldset` with spacing presets.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### FieldLegend [#fieldlegend]

Legend element for a `FieldSet`. Switch to the `label` variant to align with label sizing.

| Prop        | Type                  | Default    |
| ----------- | --------------------- | ---------- |
| `variant`   | `"legend" \| "label"` | `"legend"` |
| `className` | `string`              | -          |

### FieldGroup [#fieldgroup]

Layout wrapper that stacks `Field` components.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### Field [#field]

The core wrapper for a single field. Provides orientation control and spacing.

| Prop          | Type                                         | Default      |
| ------------- | -------------------------------------------- | ------------ |
| `orientation` | `"vertical" \| "horizontal" \| "responsive"` | `"vertical"` |
| `className`   | `string`                                     | -            |

### FieldContent [#fieldcontent]

Flex column that groups the control and descriptions when the label sits beside the control.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### FieldLabel [#fieldlabel]

Label styled for both direct inputs and nested `Field` children.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### FieldTitle [#fieldtitle]

Renders a title with label styling inside `FieldContent`.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### FieldDescription [#fielddescription]

Helper text slot that automatically balances long lines in horizontal layouts.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### FieldSeparator [#fieldseparator]

A separator between fields, with optional content rendered in the middle.

| Prop        | Type              | Default |
| ----------- | ----------------- | ------- |
| `children`  | `React.ReactNode` | -       |
| `className` | `string`          | -       |

### FieldError [#fielderror]

Displays validation errors. Pass `children` or an `errors` array.

| Prop       | Type                                       | Default |
| ---------- | ------------------------------------------ | ------- |
| `errors`   | `Array<{ message?: string } \| undefined>` | -       |
| `children` | `React.ReactNode`                          | -       |
