# Textarea

A multi-line text input with auto-grow support.

> 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="textarea" title="textarea.tsx" previewClassName="h-auto py-8">
<TextareaDemo />
</ComponentPreview>

Textarea is a styled native `<textarea>` with `field-sizing-content` for automatic height, a consistent focus ring, and disabled / invalid states. Every native attribute is forwarded to the underlying `<textarea>`.

## Installation [#installation]

<CodeTabs>
<TabsList>
<TabsTrigger value="cli">
Command
</TabsTrigger>

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

<TabsContent value="cli">
```bash
npx frakment add textarea
```
</TabsContent>

<TabsContent value="manual">
<Steps>
<Step>
Copy and paste the following code into your project.
</Step>

<ComponentSource name="textarea" title="components/ui/textarea.tsx" />

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

## Usage [#usage]

```tsx title="textarea.tsx"
import { Textarea } from "@/components/ui/textarea";
<DocsBaseSwitcher base="web" component="textarea" className="mb-6" />
```

```tsx title="textarea.tsx"
<Textarea placeholder="Write a message..." />
```

## Anatomy [#anatomy]

```tsx
<Textarea />
```

- **Textarea** — native `<textarea>` with `data-slot="textarea"`, `field-sizing-content`, `min-h-16`, and Frakment focus / disabled / invalid styling

## Examples [#examples]

### Auto-grow [#auto-grow]

Because of `field-sizing-content`, the textarea grows to fit its content without JavaScript. Set `rows` for a minimum height.

<ComponentPreview name="textarea-autogrow" title="textarea-autogrow.tsx" src="examples/textarea-autogrow.tsx" previewClassName="h-auto py-8">
<TextareaAutogrow />
</ComponentPreview>

```tsx
<Textarea
  placeholder="Type a long message..."
  defaultValue="field-sizing-content makes this grow automatically."
/>
```

### Disabled [#disabled]

<ComponentPreview name="textarea-disabled" title="textarea-disabled.tsx" src="examples/textarea-disabled.tsx" previewClassName="h-auto py-8">
<TextareaDisabled />
</ComponentPreview>

```tsx
<Textarea
  placeholder="Disabled textarea"
  disabled
  defaultValue="This field is disabled."
/>
```

### Invalid [#invalid]

Set `aria-invalid` on the textarea to trigger the destructive border and ring.

<ComponentPreview name="textarea-invalid" title="textarea-invalid.tsx" src="examples/textarea-invalid.tsx" previewClassName="h-auto py-8">
<TextareaInvalid />
</ComponentPreview>

```tsx
<Textarea
  placeholder="Invalid"
  aria-invalid
  defaultValue="This content is not allowed."
/>
```

### With Field [#with-field]

Compose with `Field` for a label and description around the textarea.

<ComponentPreview name="textarea-field" title="textarea-field.tsx" src="examples/textarea-field.tsx" previewClassName="h-auto py-8">
<TextareaField />
</ComponentPreview>

```tsx
<Field>
  <FieldLabel htmlFor="feedback">Feedback</FieldLabel>
  <Textarea id="feedback" placeholder="Share your thoughts..." rows={4} />
  <FieldDescription>We read every message.</FieldDescription>
</Field>
```

## In Context [#in-context]

### Comment box [#comment-box]

<ComponentPreview name="textarea-comment" title="textarea-comment.tsx" src="examples/textarea-comment.tsx">
<TextareaComment />
</ComponentPreview>

### Bio field with limit [#bio-field-with-limit]

<ComponentPreview name="textarea-bio" title="textarea-bio.tsx" src="examples/textarea-bio.tsx">
<TextareaBio />
</ComponentPreview>

## API Reference [#api-reference]

### Textarea [#textarea]

Extends `React.ComponentProps<"textarea">`.

<PropsTable rows={[{"name":"rows","type":"number","default":"2","description":"Initial visible rows."},{"name":"placeholder","type":"string","description":"Shown when empty."},{"name":"value","type":"string","description":"Controlled value."},{"name":"defaultValue","type":"string","description":"Uncontrolled initial value."},{"name":"onChange","type":"React.ChangeEventHandler<HTMLTextAreaElement>","description":"Fires on every keystroke."},{"name":"disabled","type":"boolean","default":"false","description":"Removes from the tab order."},{"name":"aria-invalid","type":"boolean","description":"Marks invalid; pair with aria-describedby."}]} />

## Accessibility [#accessibility]

- `Textarea` renders a native `<textarea>`. Always pair with a `Label` or `FieldLabel`.
- `rows` sets the initial height; the textarea grows with content when `field-sizing-content` is applied.
- Set `aria-invalid` and `aria-describedby` on error, same as `Input`.
- Provide a character count via `aria-describedby` when a hard limit exists.

## Best Practices [#best-practices]

- **Set a sensible rows default.** Two to four rows is enough for most forms.
- **Auto-grow with care.** `field-sizing-content` is convenient but can push the submit button off-screen in long replies.
- **Add a character count** when a limit exists.
- **Keep the submit shortcut consistent.** `Cmd+Enter` or `Ctrl+Enter` sends; `Enter` inserts a newline.
- **Do not use Textarea for a single line.** Use `Input` instead.