Get Started
Components
- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
AI Elements
Libraries
Utilities
import type * as React from "react";
import { cn } from "@/lib/utils";
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
return (
<textarea
className={cn(
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 flex field-sizing-content min-h-16 w-full rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors outline-none focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 md:text-sm",
className
)}
data-slot="textarea"
{...props}
/>
);
}
export { Textarea };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
$ bunx --bun frakment add textarea$ npx frakment add textarea$ pnpm dlx frakment add textarea$ yarn dlx frakment add textarea
Copy and paste the following code into your project.
import type * as React from "react";
import { cn } from "@/lib/utils";
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
return (
<textarea
className={cn(
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 flex field-sizing-content min-h-16 w-full rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors outline-none focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 md:text-sm",
className
)}
data-slot="textarea"
{...props}
/>
);
}
export { Textarea };Update the import paths to match your project setup.
Usage
import { Textarea } from "@/components/ui/textarea";
<DocsBaseSwitcher base="web" component="textarea" className="mb-6" /><Textarea placeholder="Write a message..." />Anatomy
<Textarea />- Textarea — native
<textarea>withdata-slot="textarea",field-sizing-content,min-h-16, and Frakment focus / disabled / invalid styling
Examples
Auto-grow
Because of field-sizing-content, the textarea grows to fit its content without JavaScript. Set rows for a minimum height.
"use client";
import { Textarea } from "@/components/ui/textarea";
export function TextareaAutogrow() {
return (
<div className="max-w-sm">
<Textarea
defaultValue="field-sizing-content makes this grow automatically without JavaScript."
placeholder="Type a long message - the textarea grows as you type."
/>
</div>
);
}<Textarea
placeholder="Type a long message..."
defaultValue="field-sizing-content makes this grow automatically."
/>Disabled
"use client";
import { Textarea } from "@/components/ui/textarea";
export function TextareaDisabled() {
return (
<div className="w-full max-w-md">
<Textarea
defaultValue="This field is disabled."
disabled
placeholder="Disabled textarea"
/>
</div>
);
}<Textarea
placeholder="Disabled textarea"
disabled
defaultValue="This field is disabled."
/>Invalid
Set aria-invalid on the textarea to trigger the destructive border and ring.
"use client";
import { Textarea } from "@/components/ui/textarea";
export function TextareaInvalid() {
return (
<div className="w-full max-w-md">
<Textarea
aria-invalid
defaultValue="This content is not allowed."
placeholder="Invalid"
/>
</div>
);
}<Textarea
placeholder="Invalid"
aria-invalid
defaultValue="This content is not allowed."
/>With Field
Compose with Field for a label and description around the textarea.
We read every message.
"use client";
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Textarea } from "@/components/ui/textarea";
export function TextareaField() {
return (
<div className="w-full max-w-md">
<Field>
<FieldLabel htmlFor="feedback">Feedback</FieldLabel>
<Textarea id="feedback" placeholder="Share your thoughts..." rows={4} />
<FieldDescription>We read every message.</FieldDescription>
</Field>
</div>
);
}<Field>
<FieldLabel htmlFor="feedback">Feedback</FieldLabel>
<Textarea id="feedback" placeholder="Share your thoughts..." rows={4} />
<FieldDescription>We read every message.</FieldDescription>
</Field>In Context
Comment box
"use client";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
export function TextareaComment() {
return (
<div className="mx-auto flex w-full max-w-sm flex-col gap-2">
<Label htmlFor="comment">Comment</Label>
<Textarea id="comment" placeholder="Write a reply…" rows={3} />
</div>
);
}Bio field with limit
Max 160 characters.
"use client";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
export function TextareaBio() {
return (
<div className="mx-auto flex w-full max-w-sm flex-col gap-2">
<Label htmlFor="bio">Bio</Label>
<Textarea id="bio" placeholder="A few words about you…" rows={4} />
<p className="text-muted-foreground text-xs">Max 160 characters.</p>
</div>
);
}API Reference
Textarea
Extends React.ComponentProps<"textarea">.
| Prop | Type | Default | Description |
|---|---|---|---|
rows | number | 2 | Initial visible rows. |
placeholder | string | — | Shown when empty. |
value | string | — | Controlled value. |
defaultValue | string | — | Uncontrolled initial value. |
onChange | React.ChangeEventHandler<HTMLTextAreaElement> | — | Fires on every keystroke. |
disabled | boolean | false | Removes from the tab order. |
aria-invalid | boolean | — | Marks invalid; pair with aria-describedby. |
Accessibility
Textarearenders a native<textarea>. Always pair with aLabelorFieldLabel.rowssets the initial height; the textarea grows with content whenfield-sizing-contentis applied.- Set
aria-invalidandaria-describedbyon error, same asInput. - Provide a character count via
aria-describedbywhen a hard limit exists.
Best Practices
- Set a sensible rows default. Two to four rows is enough for most forms.
- Auto-grow with care.
field-sizing-contentis 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+EnterorCtrl+Entersends;Enterinserts a newline. - Do not use Textarea for a single line. Use
Inputinstead.