shadcn.io is an independent project built on shadcn/ui
On this page9 sections
Textarea is a native multi-line text box for a comment, a message, a bio or a support note. Its classes include field-sizing-content, so in browsers that support CSS field-sizing it starts small and grows with the text instead of scrolling.
For a name, an email address or anything else that stays on one line, use an Input. To put a button or a character count inside the textarea's border, wrap it in an Input Group.
Installation
Anatomy

Usage
import { Textarea } from "@/components/ui/textarea";aria-label names the textarea when nothing on screen does. In a form, give it a visible label with Field instead, as the Field demo does.
<Textarea
aria-label="Message"
className="max-w-xs"
placeholder="Type your message here."
/>Accessibility
Textarea renders a native <textarea>, so the browser handles typing, selection, scrolling and line breaks: Enter adds a new line rather than submitting the form, and Tab moves on rather than typing a tab. What it needs from you is a name. Inside Field, FieldLabel points at it with no ids to write, invalid on Field sets aria-invalid on it, and FieldDescription and FieldError are read out as its description. Without a visible label, set aria-label.
Demos
Field
Message as the label, a line of help, then the box. The description sits between the label and the textarea, so people see it before they start typing, which suits instructions about what to write. Field links the label to the textarea, so clicking Message focuses it.
Max height
Ten lines of meeting notes in a box capped by max-h-40. The textarea grows with its text up to 160 pixels, then scrolls, and shrinks again as lines are deleted. Cap any box where a long answer would push the rest of the form off the screen. In a browser without field-sizing, it keeps its starting height and scrolls.
Disabled
The Message box is disabled, so it can't be focused or typed in, shows a not-allowed cursor, and stays out of the form data. data-disabled set to true on Field fades the label to match. Use it for a message that can't be edited yet, such as one waiting on an earlier choice.
Invalid
The field is marked invalid with invalid on Field alone, which passes aria-invalid to the box: its border and focus ring turn to the destructive color, the label follows, and a screen reader hears that the text is wrong. The line under it asks for a valid message. In your form, say what's wrong instead, in a FieldError you show only while it applies.
Button
A message box with a full-width Send message button under it, in a plain grid with a small gap. Use it when sending that text is the whole form, such as a feedback widget or a reply box. To put the button inside the textarea's border instead, use an Input Group with an addon at block-end.
RTL
Feedback in Arabic, with dir set to rtl on the Field, so the label, the caret and the note under the box start from the right. rows is 4, which sets the starting height only in browsers without field-sizing. Use it when the page or the field is in Arabic or Hebrew.
FAQ
How do I make a Textarea grow with its content in React?
In browsers that support the CSS field-sizing property it already does. The Textarea's classes include field-sizing-content, so it grows with its text from a min-h-16 minimum. In a browser without field-sizing, it keeps a fixed height and scrolls.
Add autoResize to cover those browsers too. Where field-sizing is missing, UI SDK sets the height from the text's scrollHeight on every change, and a max height class still caps it, past which the box scrolls.
How do I set a maximum height on a Textarea?
Add a max height class such as max-h-40, as the Max height demo does. The textarea grows up to it and then scrolls its text. Add resize-none too if people shouldn't drag the corner to make it taller.
The other end works the same way: the box starts at its min-h-16 minimum, and a class such as min-h-24 makes it start taller. With autoResize on, UI SDK stops at the same max height, and the box scrolls past it.
Why doesn't rows change the height of my Textarea?
In browsers that support field-sizing, the field-sizing-content class sizes the box to its text, and rows no longer sets its height. Set a starting height with a min height class such as min-h-32 instead.
To get the browser's own sizing back for one Textarea, add field-sizing-fixed to its classes, which replaces field-sizing-content, and rows works again. The RTL demo sets rows to 4, which only shows in a browser without field-sizing.
How do I add a label and help text to a Textarea?
Put it in a Field with a FieldLabel, as the Field demo does, and Field links the label to it. For help text, add a FieldDescription, which Field names in the textarea's aria-describedby, so a screen reader reads it when the box takes focus.
How do I show a validation error on a Textarea?
Set invalid on its Field, as the Invalid demo does, which passes aria-invalid to the Textarea, or set aria-invalid on the Textarea alone. Either way its border and focus ring turn to the destructive color and a screen reader hears that the text is invalid.
Put the message in a FieldError, which is announced as an alert when it appears. It renders whenever it has content, so show it only while the text is wrong.
How do I limit and count characters in a Textarea?
Set maxLength to the limit, and the browser stops accepting text past it, pasted text included. To show a count such as 120 / 280, keep the value in state and print its length in the field's description.
Pass value and update it in onChange from event.target.value. Leave the count out of a live region, or a screen reader reads it after every key.
How do I send a Textarea's message with Enter and keep Shift+Enter for new lines?
Set submitShortcut to enter on the Textarea. Enter then submits the form it sits in through its requestSubmit method, which runs the browser's validation first, and Shift+Enter adds a line. Pass onSubmit to run your own code with the text instead, or set submitShortcut to mod+enter to keep Enter for new lines.
UI SDK skips the shortcut while an input method is composing text, such as Japanese or Chinese input, so pressing Enter to confirm a word doesn't send the message.
Does the Textarea work with forms and form libraries in React?
Yes. It renders a native <textarea>, so with a name its text is part of the form's data, and required stops the form from submitting while it's empty. Read it with FormData in your submit handler.
React Hook Form's register spreads onto it, since the component passes its ref and handlers through to the <textarea>. Show the library's errors as the validation answer describes.
API Reference
Textarea
<textarea> data-slot="textarea"
value?string
The value, for a controlled field.
defaultValue?string
The value it starts with. A form reset returns here.
onValueChange?(value: string, details: ChangeDetails<InputValueChangeReason>) → void
Called when the user changes the value: typing ("input-change"), a Clear part ("clear-press"), a form reset ("reset") or a controller ("imperative"). details.cancel() keeps the value as it was.
- Type
(value: string, details: ChangeDetails<InputValueChangeReason>) → void- Parameters
value– stringdetails– ChangeDetails<InputValueChangeReason>- Returns
void
autoResize?boolean
Grows and shrinks with the text. Bound it with CSS min-height and max-height; past the maximum, it scrolls.
- Default
false
controller?InputController
Reads and writes the field from anywhere. Create one with createInputController().
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Disables the field.
onSubmit?(value: string, details: TextareaSubmitDetails) → void
Runs on the submit shortcut, unless an input method is composing. Without it, the shortcut submits the form the textarea is in. With neither, the key is left alone, so Enter adds a line.
- Type
(value: string, details: TextareaSubmitDetails) → void- Parameters
value– stringdetails– TextareaSubmitDetails- Returns
void
readOnly?boolean
Makes the field read-only.
required?boolean
Makes the field required.
submitShortcut?"enter" | "mod+enter"
Which keys submit: "enter", with Shift+Enter for a new line, or "mod+enter", with Enter for a new line. Without it, Enter always starts a new line.
- Type
"enter" | "mod+enter"
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
data-disabled?string
Present when the field is disabled, by its own prop or its Field.
data-filled?string
Present while the field holds any text.
data-readonly?string
Present when the field is read-only.
data-required?string
Present when the field is required.












