--- title: Field description: A component that provides labelling and validation for form controls. links: doc: https://base-ui.com/react/components/field#api-reference --- ## Installation CLI Manual ```bash npx shadcn@latest add @coss/field ``` Install the following dependencies: ```bash npm install @base-ui/react ``` Import the following variables into your CSS file ```css @theme inline { --color-destructive-foreground: var(--destructive-foreground); } :root { --destructive-foreground: var(--color-red-700); } .dark { --destructive-foreground: var(--color-red-400); } ``` Copy and paste the following code into your project. Update the import paths to match your project setup. ## Usage ```tsx import { Field, FieldDescription, FieldError, FieldLabel, FieldValidity, } from "@/components/ui/field" import { Input } from "@/components/ui/input" ``` ```tsx Name Visible on your profile Please enter a valid name {(validity) => ( {validity.error &&

{validity.error}

} )}
``` ## API Reference ### Field Root component. Styled wrapper for `Field.Root` from Base UI with flex column layout. ### FieldLabel Label for the field. Styled wrapper for `Field.Label` from Base UI. ### FieldItem Container for field items. Styled wrapper for `Field.Item` from Base UI. ### FieldDescription Description text for the field. Styled wrapper for `Field.Description` from Base UI with muted foreground color. ### FieldError Error message for the field. Styled wrapper for `Field.Error` from Base UI with destructive foreground color. ### FieldControl Alias for `Field.Control` from Base UI. Use this to register a custom or third-party control with the field context so it participates in labelling, validation, and error state. Note that `Textarea` does not require `FieldControl` — it wraps `Field.Control` internally and integrates with `Field` the same way `Input` and other built-in controls do. ### FieldValidity Alias for `Field.Validity` from Base UI. ## Examples ### Required Field ### Disabled Field ### With Error Enter an invalid email address and press enter to see the error. ### With Validity ### Input Group ### Autocomplete Field ### Combobox Field ### Combobox Multiple Field ### Textarea Field ### Select Field ### Checkbox Field ### Checkbox Group Field ### Radio Group Field ### Switch Field ### Slider Field ### Number Field ### Complete Form Example