shadcn.io is not affiliated with official shadcn/ui
Textarea examples · Standard
Simple Textarea for React
A plain textarea with a placeholder and no surrounding chrome.
The starting point: a Textarea with a placeholder and nothing around it. It renders a native textarea with the theme's border, focus ring and invalid styles, and grows with its text from a minimum height in browsers that support field-sizing. Use it where the context already says what to type; in a form, add a label.
Preview
Installation
FAQ
Can placeholder text replace a visible label?
No. The placeholder disappears as soon as people type, so they lose track of what the field is for, and it isn't a reliable accessible name. This demo sets aria-label because it has no visible label; in a form, put the Textarea in a Field with a FieldLabel, as the Textarea with Label example does.
How do I prevent users from resizing the textarea?
Add resize-none to its classes to hide the drag handle, or resize-y to allow height changes only. The Textarea already grows with its content where field-sizing is supported, so many layouts don't need the handle at all.
What's the default height if I don't specify rows?
The Textarea has field-sizing-content and min-h-16: it starts at that minimum and grows with each line of text. In browsers without field-sizing it keeps the minimum height and scrolls. Set a max height such as max-h-40 to stop it growing past a point.
Should I use value or defaultValue for this textarea?
Neither is needed here: the Textarea is uncontrolled and the browser keeps what's typed, which the form submits under its name. Set a default value to prefill it, and bind the value from state only when you react to every change, such as a character count.
Related
- Textarea with LabelA textarea with a visible label above it
- Short TextareaA compact textarea fixed at three rows
- Textarea with DescriptionA textarea with a description between its
- Disabled TextareaA disabled textarea that is dimmed and
- Input with LabelA text input with a label above it
- Read-only TextareaA read-only textarea whose text can be