shadcn.io is not affiliated with official shadcn/ui
When vertical space is tight, in a sidebar, a dense settings panel or a quick note, a Textarea three lines tall is enough. The Textarea normally grows with its content from a minimum height; here field-sizing-fixed turns that off, min-h-0 drops the minimum, and rows sets the height to three lines, scrolling past them.
Preview
Installation
FAQ
Why does the short Textarea need field-sizing-fixed and min-h-0?
The Textarea has field-sizing-content, so in browsers that support it the height follows the text and rows is ignored, and min-h-16 keeps it at least that tall. field-sizing-fixed brings back the rows height and min-h-0 removes the minimum, so three rows means three lines everywhere.
What happens when users type more than three lines?
The Textarea keeps its height and scrolls, with a scrollbar once the text overflows. Keyboard and screen reader users can still reach every line. If it should grow instead, drop field-sizing-fixed and cap it with a max height such as max-h-40.
Can I adjust the rows to make it even more compact?
Yes, rows takes any number. Two rows still reads as a multi-line field; at one row, use an Input instead, which says single line to everyone.
Should I allow users to resize short textareas?
The browser's resize handle stays on by default, which helps people who type more than you planned for. Add resize-none if the layout around it must not move, or resize-y to allow height changes only.
Related
- Simple TextareaA plain textarea with a placeholder and
- Textarea with Inline LabelA three-row textarea with its label
- Textarea with LabelA textarea with a visible label above it
- Multiple Textareas - Different Sizes FieldThree textareas of two, four and eight
- Disabled TextareaA disabled textarea that is dimmed and
- Read-only TextareaA read-only textarea whose text can be