---
title: "Form"
description: "A form around its fields. It sets when every field checks its value, shows server errors on the right field, and gives your submit the values."
url: https://gelatinui.com/components/form
markdown_url: https://gelatinui.com/components/form.md
access: free
install: "npx shadcn@latest add @gelatin-ui/form"
registry_item: https://gelatinui.com/r/form.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Form

> A form around its fields. It sets when every field checks its value, shows server errors on the right field, and gives your submit the values.

Page: https://gelatinui.com/components/form

## When to use it

Best for: The fields of one task, with one validation mode, server errors by field, and a submit.

- Use it around the fields of one task, with the submit Button in the last row.
- Put each control in a `Field` with a `name`. `onFormSubmit` gets the values as an object by that name.
- Pass the errors of the server in `errors`, by field name. Each error shows until the user changes the value.
- `validationMode` sets one mode for every field: `onBlur` (the default), `onChange`, or `onSubmit`. A Field with its own mode keeps it.

## When not to use it

- For one control outside a form, with its label, help, and error, use a [Field](https://gelatinui.com/components/field.md).

## Notes for agents

- Give each `Field` a `name`: `onFormSubmit` gets the values as an object keyed by those names.
- Pass server errors in `errors`, by field name; each one shows until the user changes the value.

## Anatomy

```text
Form
```

## API reference

### Form

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

Also takes every prop of Base UI `Form`: https://base-ui.com/react/components/form

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Form | `form` |  |  |  |

## Usage

`onFormSubmit` gets the values as an object by field name. Put the errors of the server in `errors`: each shows in the `FieldError` of its field until the user changes the value.

The sample also uses `button`, `input`, which this add does not write. One command adds them with this item:

```bash
npx shadcn@latest add @gelatin-ui/form @gelatin-ui/button @gelatin-ui/input
```

```tsx title="invite-form.tsx"
import { useState } from "react";

import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";

type InviteValues = { email: string };

export function InviteForm({ invite }: { invite: (email: string) => Promise<string | null> }) {
  const [errors, setErrors] = useState<Record<string, string>>({});
  const [pending, setPending] = useState(false);
  async function send(values: InviteValues) {
    setPending(true);
    try {
      const error = await invite(values.email);
      setErrors(error === null ? {} : { email: error });
    } finally {
      setPending(false);
    }
  }
  return (
    <Form<InviteValues>
      errors={errors}
      onFormSubmit={(values) => {
        void send(values);
      }}
    >
      <Field name="email">
        <FieldLabel>Email</FieldLabel>
        <Input type="email" required autoComplete="email" />
        <FieldError />
      </Field>
      <div className="flex pt-1">
        <Button type="submit" busy={pending}>
          Send invite
        </Button>
      </div>
    </Form>
  );
}
```

## Compose

Build it with:

- [Field](https://gelatinui.com/components/field.md): Names each control and shows its error text.
- [Input](https://gelatinui.com/components/input.md): Takes short text.
- [Textarea](https://gelatinui.com/components/textarea.md): Takes long text.
- [Stepper](https://gelatinui.com/components/stepper.md): Shows the steps of a long form.
- [Dialog](https://gelatinui.com/components/dialog.md): Holds a short form over the page.
- [Button](https://gelatinui.com/components/button.md): Submits or moves to the next step.
- [Alert](https://gelatinui.com/components/alert.md): Shows an error of the whole form.

Rules:

- Touch targets (`touch-targets`): Give every control a hit area of at least 44 px on touch screens, even when it looks smaller.
- Group with a Frame (`group-in-frames`): Put related panels in one `Frame` with its header and footer outside the panels, and keep a plain `Card` for one block of content.
- Name every control (`label-every-control`): Give every field a visible `Label` (or a `Field`), and every icon button a `Tooltip` or an `aria-label`.
- Labels real apps use (`real-labels`): Write the button and menu labels that real apps use ("Create API key", "Invite members"), with no "…" at the end.

Patterns: `gelatin://patterns/form-flow`

## Add it

```bash
npx shadcn@latest add @gelatin-ui/form
```

It adds 12 registry items: 9 files, 1932 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@xstate/react`, `clsx`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Field](https://gelatinui.com/components/field.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Field](https://gelatinui.com/components/field.md)
- [Input](https://gelatinui.com/components/input.md)
- [Button](https://gelatinui.com/components/button.md)
- [Checkbox](https://gelatinui.com/components/checkbox.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Enter | Sends the form from a text field. When a field is invalid, the focus moves to the first invalid field. |

## Accessibility

Form is a Base UI `Form`, a native `<form>`. Put each control in a `Field`, so its label, help, and error link to it for screen readers.

When a submit finds an invalid field, the focus moves to the first invalid field. A screen reader then reads its name and its error.

An error from `errors` shows in the `FieldError` of its field and links to the control, the same as an error of the browser check.

Give the submit Button `loading` while the request runs. It sets `aria-busy`, keeps the focus, and blocks a second press.
