# Form

> Accessible form root from Base UI.

Registry name: `form`. HTML docs: https://ui.anuragroy.dev/component/form.

## Install

```bash
npx shadcn@latest add https://ui.anuragroy.dev/r/form.json
```

If the website is down: `npx shadcn@latest add https://raw.githubusercontent.com/anurag-roy/ui.anuragroy.dev/main/public/r/form.json`.

Registry JSON: https://ui.anuragroy.dev/r/form.json (GitHub: https://raw.githubusercontent.com/anurag-roy/ui.anuragroy.dev/main/public/r/form.json).

## Import

Import paths follow the consumer `components.json` aliases. After a default install:

```tsx
import { Form } from "@/components/ui/form"
```

## Usage

```tsx
import { Button } from "@/components/ui/button"
import { Form } from "@/components/ui/form"
import {
  TextField,
  TextFieldError,
  TextFieldInput,
  TextFieldLabel,
} from "@/components/ui/text-field"

export function Example() {
  return (
    <Form
      className="flex flex-col gap-3"
      onSubmit={(event) => event.preventDefault()}
    >
      <TextField name="name">
        <TextFieldLabel>Name</TextFieldLabel>
        <TextFieldInput placeholder="Your name" required />
        <TextFieldError match="valueMissing">Name is required.</TextFieldError>
      </TextField>
      <Button type="submit">Save</Button>
    </Form>
  )
}
```

## API

### Form

Base UI Form. Native form props plus validation wiring for Field children.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onSubmit` | React.FormEventHandler<HTMLFormElement> | — | Native submit handler. Call `event.preventDefault()` for client-side forms. |

## See also

- [HTML page](https://ui.anuragroy.dev/component/form): Preview and the same docs in the site chrome.
- [Registry item](https://ui.anuragroy.dev/r/form.json): Source files and dependencies.
- [Catalog](https://ui.anuragroy.dev/component): All components.
- [llms.txt](https://ui.anuragroy.dev/llms.txt): Agent index for this library.
