Textarea
Multi-line text input for longer free-form answers - mission notes, biographies, feedback, or any response that exceeds a single line. Styled via the <textarea> element selector with a matching .textarea mirror class so consumers can opt into the same visual result on wrapped or custom markup. Composes with labels, descriptions, and error messages in the same pattern as other form controls.
Usage
When to use
- Free-text answers longer than a single line
- Comments, notes, descriptions, bios, mission logs
- Any field where users need to see multiple lines as they type
When not to use
- Single-line responses - use
<input type="text"> - Rich text with formatting - use a rich text editor component
- Numeric or date values - use the appropriate typed input
Do
- Pair every textarea with a visible
<label> - Set
rowsto a sensible default for the expected answer length - Provide a character count when
maxlengthis enforced - Communicate validation errors with both text and
aria-invalid
Don't
- Use a textarea for a single-line field
- Hide the label or use placeholder text as a substitute
- Disable resize unless there is a clear layout reason
API
Slots
| Slot | Required | Description |
|---|---|---|
label | Yes | Visible label text for the textarea. |
placeholder | - | Placeholder text shown when the textarea is empty. |
value | - | Pre-filled content of the textarea. |
helper | - | Helper text rendered below the textarea. |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | - | HTML id of the textarea. Used to associate the label. Auto-generated when omitted. |
is_disabled | boolean | - | Disables the control. |
is_readonly | boolean | - | Renders the control as read-only. |
is_required | boolean | - | Marks the control as required. |
is_invalid | boolean | - | Marks the control as invalid. Renders aria-invalid="true" when set. |
helper_id | string | - | ID of the helper element; the control gets aria-describedby pointing to it. |
use_autoresize | boolean | - | Opts in to auto-resize. JS grows the field to fit its content as the user types. |
has_counter | boolean | - | Renders a live character counter below the field, updated as the user types. Reads the maxlength attribute for the total. |
classes | array | - | Additional CSS class words merged into the root element. |
attributes | object | - | Additional HTML attributes spread on the root element. |
Classes
| Class | Capability | Default | Description |
|---|---|---|---|
.sm | Size | - | Small. |
.md | Size | Yes | Medium. |
.lg | Size | - | Large. |
Attributes
| Attribute | Set by | Required | Description |
|---|---|---|---|
data-textarea-autoresize | Consumer | - | Grows the field to fit its content. |
data-textarea-counter | Consumer | - | Live remaining-character count updated as the user types. |
Examples
Sizes
Sm, default, and lg variants stacked vertically. Font size and padding scale together.
With character count
Textarea with maxlength and a live character counter.
Auto-resize
Textarea that grows as the user types, up to a max height.
Disabled
Disabled state.
Invalid
Textarea in an error state with a visible error message.
Required
A required field, where the preceding label picks up its asterisk from the control rather than from any markup of its own.
Accessibility
- WCAG 2.2 AA
- Every textarea has a programmatic label
- Character count is announced politely to screen readers
- Validation state exposed via
aria-invalidand a linked error message - Focus ring is visible and meets contrast requirements
Progressive enhancement
- No JS: native
<textarea>with the user-agent resize handle - With JS:
textarea.jslayers in two independent, opt-in behaviors. Setuse_autoresize: true(or adddata-textarea-autoresizedirectly to a hand-authored classless textarea) to grow the field to fit its content on every keystroke, and once on load so pre-filled content is not clipped. Sethas_counter: true(or adddata-textarea-counter="<id>"directly, pointing at a.textarea-counterelement - a baredata-textarea-counterfalls back to a sibling.textarea-counter) to show a live "used / total" count read from themaxlengthattribute and updated as the user types.
Related
- textfield - single-line counterpart