# Field

URL: https://ark-ui.com/docs/react/components/field
Markdown: https://ark-ui.com/docs/react/components/field.md

Provides a flexible container for form inputs, labels, and helper text.

---

---
id: field
title: Field
description: Provides a flexible container for form inputs, labels, and helper text.
---



## Anatomy



```tsx
<Field.Root>
  <Field.Label>
    <Field.Indicator />
  </Field.Label>
  <Field.Input />
  <Field.Textarea />
  <Field.Select />
  <Field.HelperText />
  <Field.ErrorText />
</Field.Root>
```

## Examples

`Field` provides `invalid`, `disabled`, `required`, and `readOnly` context to form elements. Most Ark UI components read
it natively, and it also works with standard HTML form elements.

### Input

Use `Field.Input` for a standard input.

```tsx
import { Field } from '@ark-ui/react/field'
import styles from 'styles/field.module.css'

export const Input = () => (
  <Field.Root className={styles.Root}>
    <Field.Label className={styles.Label}>Label</Field.Label>
    <Field.Input className={styles.Input} />
    <Field.HelperText className={styles.HelperText}>Some additional Info</Field.HelperText>
    <Field.ErrorText className={styles.ErrorText}>Error Info</Field.ErrorText>
  </Field.Root>
)
```

### Disabled

Set `disabled` on the root to disable the control and mark every part with `data-disabled`.

```tsx
import { Field } from '@ark-ui/react/field'
import styles from 'styles/field.module.css'

export const Disabled = () => (
  <Field.Root className={styles.Root} disabled>
    <Field.Label className={styles.Label}>Label</Field.Label>
    <Field.Input className={styles.Input} />
    <Field.HelperText className={styles.HelperText}>Some additional Info</Field.HelperText>
    <Field.ErrorText className={styles.ErrorText}>Error Info</Field.ErrorText>
  </Field.Root>
)
```

### Invalid

Set `invalid` to show the error text and mark the control with `aria-invalid`. The error text stays mounted and hidden
while the field is valid.

```tsx
import { Field } from '@ark-ui/react/field'
import styles from 'styles/field.module.css'

export const Invalid = () => (
  <Field.Root className={styles.Root} invalid>
    <Field.Label className={styles.Label}>Email</Field.Label>
    <Field.Input className={styles.Input} placeholder="me@example.com" />
    <Field.ErrorText className={styles.ErrorText}>This is an error text</Field.ErrorText>
  </Field.Root>
)
```

### Indicator

`Field.Indicator` is shown only when its `type` matches the field state: `required`, `invalid`, `valid` or `validating`.
Use it inside the label to show a required marker.

```tsx
import { Field } from '@ark-ui/react/field'
import styles from 'styles/field.module.css'

export const Indicator = () => (
  <Field.Root className={styles.Root} required>
    <Field.Label className={styles.Label}>
      Username
      <Field.Indicator type="required">*</Field.Indicator>
    </Field.Label>
    <Field.Input className={styles.Input} />
  </Field.Root>
)
```

### Validation

The field validates the control natively, using attributes like `required` and `type="email"`. Set `validationMode` to
choose when results show (`onSubmit`, `onBlur` or `onChange`). Pass `match` to `Field.ErrorText` to show it only for one
native failure, such as `valueMissing` or `typeMismatch`.

```tsx
import { Field } from '@ark-ui/react/field'
import button from 'styles/button.module.css'
import styles from 'styles/field.module.css'

export const Validation = () => (
  <form className="stack" noValidate onSubmit={(event) => event.preventDefault()}>
    <Field.Root className={styles.Root} required validationMode="onBlur">
      <Field.Label className={styles.Label}>
        Email
        <Field.Indicator type="required">*</Field.Indicator>
      </Field.Label>
      <Field.Input className={styles.Input} type="email" placeholder="me@example.com" />
      <Field.HelperText className={styles.HelperText}>We'll never share your email.</Field.HelperText>
      <Field.ErrorText className={styles.ErrorText} match="valueMissing">
        Email is required
      </Field.ErrorText>
      <Field.ErrorText className={styles.ErrorText} match="typeMismatch">
        Enter a valid email address
      </Field.ErrorText>
    </Field.Root>
    <button className={button.Root} type="submit">
      Submit
    </button>
  </form>
)
```

### Custom Validation

Pass `validate` to run your own rules. Return an error message, a list of messages, or nothing when the value is valid.
It can also return a promise. The messages are available as `errors` on the field context.

```tsx
import { Field } from '@ark-ui/react/field'
import button from 'styles/button.module.css'
import styles from 'styles/field.module.css'

const reserved = ['admin', 'root', 'support']

export const CustomValidation = () => (
  <form className="stack" noValidate onSubmit={(event) => event.preventDefault()}>
    <Field.Root
      className={styles.Root}
      required
      validationMode="onChange"
      validate={({ value }) => {
        if (value.length > 0 && value.length < 3) return 'Use at least 3 characters'
        if (reserved.includes(value.toLowerCase())) return 'This username is reserved'
      }}
    >
      <Field.Label className={styles.Label}>Username</Field.Label>
      <Field.Input className={styles.Input} />
      <Field.Context>
        {(field) => <Field.ErrorText className={styles.ErrorText}>{field.errors[0]}</Field.ErrorText>}
      </Field.Context>
    </Field.Root>
    <button className={button.Root} type="submit">
      Submit
    </button>
  </form>
)
```

### Server Errors

Pass `errors` to show errors from outside the field, such as a server response. The field is invalid while `errors` is
not empty.

```tsx
import { Field } from '@ark-ui/react/field'
import { useState } from 'react'
import button from 'styles/button.module.css'
import styles from 'styles/field.module.css'

export const ServerErrors = () => {
  const [errors, setErrors] = useState<string[]>([])

  return (
    <form
      className="stack"
      onSubmit={(event) => {
        event.preventDefault()
        setErrors(['This email is already registered'])
      }}
    >
      <Field.Root className={styles.Root} errors={errors}>
        <Field.Label className={styles.Label}>Email</Field.Label>
        <Field.Input className={styles.Input} type="email" name="email" defaultValue="taken@example.com" />
        <Field.HelperText className={styles.HelperText}>Submit to check the email with the server.</Field.HelperText>
        <Field.Context>
          {(field) => <Field.ErrorText className={styles.ErrorText}>{field.errors[0]}</Field.ErrorText>}
        </Field.Context>
      </Field.Root>
      <button className={button.Root} type="submit">
        Submit
      </button>
    </form>
  )
}
```

### Textarea

Use `Field.Textarea` for a textarea.

```tsx
import { Field } from '@ark-ui/react/field'
import styles from 'styles/field.module.css'

export const Textarea = () => (
  <Field.Root className={styles.Root}>
    <Field.Label className={styles.Label}>Label</Field.Label>
    <Field.Textarea className={styles.Textarea} />
    <Field.HelperText className={styles.HelperText}>Some additional Info</Field.HelperText>
    <Field.ErrorText className={styles.ErrorText}>Error Info</Field.ErrorText>
  </Field.Root>
)
```

### Textarea Autoresize

Set `autoresize` on `Field.Textarea` to grow it as the user types.

```tsx
import { Field } from '@ark-ui/react/field'
import styles from 'styles/field.module.css'

export const TextareaAutoresize = () => (
  <Field.Root className={styles.Root}>
    <Field.Label className={styles.Label}>Label</Field.Label>
    <Field.Textarea className={styles.Textarea} autoresize />
    <Field.HelperText className={styles.HelperText}>Some additional Info</Field.HelperText>
    <Field.ErrorText className={styles.ErrorText}>Error Info</Field.ErrorText>
  </Field.Root>
)
```

### Select

Use `Field.Select` for a native select.

```tsx
import { Field } from '@ark-ui/react/field'
import styles from 'styles/field.module.css'

export const Select = () => (
  <Field.Root className={styles.Root}>
    <Field.Label className={styles.Label}>Label</Field.Label>
    <Field.Select className={styles.Select}>
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
      <option value="3">Option 3</option>
    </Field.Select>
    <Field.HelperText className={styles.HelperText}>Some additional Info</Field.HelperText>
    <Field.ErrorText className={styles.ErrorText}>Error Info</Field.ErrorText>
  </Field.Root>
)
```

### Checkbox

Wrap a `Checkbox` in `Field`.

```tsx
import { Checkbox } from '@ark-ui/react/checkbox'
import { Field } from '@ark-ui/react/field'
import { CheckIcon, MinusIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
import field from 'styles/field.module.css'

export const WithField = () => (
  <Field.Root className={field.Root} data-inline>
    <Checkbox.Root className={styles.Root}>
      <Checkbox.Control className={styles.Control}>
        <Checkbox.Indicator className={styles.Indicator}>
          <CheckIcon />
        </Checkbox.Indicator>
        <Checkbox.Indicator className={styles.Indicator} indeterminate>
          <MinusIcon />
        </Checkbox.Indicator>
      </Checkbox.Control>
      <Checkbox.Label className={styles.Label}>Label</Checkbox.Label>
      <Checkbox.HiddenInput />
    </Checkbox.Root>
    <Field.HelperText className={field.HelperText}>Additional Info</Field.HelperText>
    <Field.ErrorText className={field.ErrorText}>Error Info</Field.ErrorText>
  </Field.Root>
)
```

### Root Provider

Use `RootProvider` with the `useField` hook to access the state and methods from outside the component.

```tsx
import { Field, useField } from '@ark-ui/react/field'
import { useState } from 'react'
import styles from 'styles/field.module.css'
import button from 'styles/button.module.css'

export const RootProvider = () => {
  const [invalid, setInvalid] = useState(false)
  const field = useField({ invalid })

  return (
    <>
      <button className={button.Root} style={{ marginBottom: '1rem' }} onClick={() => setInvalid((prev) => !prev)}>
        Toggle Invalid
      </button>
      <Field.RootProvider className={styles.Root} value={field}>
        <Field.Label className={styles.Label}>Label</Field.Label>
        <Field.Input className={styles.Input} />
        <Field.HelperText className={styles.HelperText}>Some additional Info</Field.HelperText>
        <Field.ErrorText className={styles.ErrorText}>Error Info</Field.ErrorText>
      </Field.RootProvider>
    </>
  )
}
```

### Custom Control

Use `Field.Context` or the `useFieldContext` hook to read the field state and wire up a custom control.

```tsx
import { Field } from '@ark-ui/react/field'
import styles from 'styles/field.module.css'

export const CustomControl = () => (
  <Field.Root className={styles.Root} invalid>
    <Field.Label className={styles.Label}>Any Control</Field.Label>
    <Field.Context>{(context) => <input className={styles.Input} {...context.getInputProps()} />}</Field.Context>
    <Field.HelperText className={styles.HelperText}>Uses getInputProps() for maximum flexibility</Field.HelperText>
    <Field.ErrorText className={styles.ErrorText}>This field has an error</Field.ErrorText>
  </Field.Root>
)
```

## API Reference

### Root

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`dirty`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the field's value has been changed from its initial value.
Useful when the field state is controlled by an external library.

**`disabled`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether the field is disabled. Also inherited from a surrounding native `<fieldset disabled>`.

**`errors`**
Type: `string | string[]`
Required: false
Default Value: `undefined`
Description: Errors from outside the field, such as a server response. They mark the field invalid
until the user changes the value, and show again when different errors are passed or the form is submitted.

**`ids`**
Type: `Partial<{ root: string; control: string; label: string; errorText: string; helperText: string }>`
Required: false
Default Value: `undefined`
Description: The ids of the elements. Useful for composition.

**`invalid`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the field is invalid, regardless of computed validity.
Use for app-level errors (e.g. server errors) the machine cannot compute itself.

**`onValidityChange`**
Type: `(details: ValidityChangeDetails) => void`
Required: false
Default Value: `undefined`
Description: Called when the committed validity changes.

**`readOnly`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether the field is read-only.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldRootState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

**`required`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether the field is required.

**`target`**
Type: `string`
Required: false
Default Value: `undefined`
Description: The item whose control the field tracks, for fields composed of multiple controls.
The tracked control id (and the root label's `htmlFor`) become `{id}:item:{target}`.
`ids.control` overrides this.

**`touched`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the field has been touched.
Useful when the field state is controlled by an external library.

**`validate`**
Type: `(details: ValidateDetails) => ValidateResult | Promise<ValidateResult>`
Required: false
Default Value: `undefined`
Description: Custom validation, run against the value and the native validity snapshot.
May return a promise; a newer validation run supersedes an in-flight one.

**`validationMode`**
Type: `ValidationMode`
Required: false
Default Value: `"onSubmit"`
Description: When validation results become visible.

### ErrorText

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`id`**
Type: `string`
Required: false
Default Value: `undefined`
Description: Overrides the generated id. Use when two error texts share the same `match`.

**`match`**
Type: `boolean | ValidityMatch`
Required: false
Default Value: `undefined`
Description: Narrows when the error text shows:
- a `ValidityState` key shows it only for that native failure
- `true` forces it visible (e.g. driven by an external form library)
- omitted shows it whenever the field is invalid

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldErrorTextState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### HelperText

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldHelperTextState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### Indicator

#### Props

**`type`**
Type: `IndicatorType`
Required: true
Default Value: `undefined`
Description: The state the indicator reflects. Hidden (not unmounted) unless the state
matches, so CSS transitions survive:
- `required`: the field is required (e.g. an asterisk)
- `invalid`: committed validity is invalid
- `valid`: committed validity is valid — a pristine field shows neither
- `validating`: an async validation is in flight (e.g. a spinner)

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldIndicatorState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### Input

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldInputState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### Item

#### Props

**`value`**
Type: `string`
Required: true
Default Value: `undefined`
Description: undefined

### Label

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldLabelState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### RootProvider

#### Props

**`value`**
Type: `UseFieldReturn`
Required: true
Default Value: `undefined`
Description: undefined

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldRootProviderState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### Select

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldSelectState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### Textarea

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`autoresize`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether the textarea should autoresize

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<FieldTextareaState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.
