Skip to main content

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 rows to a sensible default for the expected answer length
  • Provide a character count when maxlength is 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​

SlotRequiredDescription
labelYesVisible 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​

PropTypeDefaultDescription
idstring-HTML id of the textarea. Used to associate the label. Auto-generated when omitted.
is_disabledboolean-Disables the control.
is_readonlyboolean-Renders the control as read-only.
is_requiredboolean-Marks the control as required.
is_invalidboolean-Marks the control as invalid. Renders aria-invalid="true" when set.
helper_idstring-ID of the helper element; the control gets aria-describedby pointing to it.
use_autoresizeboolean-Opts in to auto-resize. JS grows the field to fit its content as the user types.
has_counterboolean-Renders a live character counter below the field, updated as the user types. Reads the maxlength attribute for the total.
classesarray-Additional CSS class words merged into the root element.
attributesobject-Additional HTML attributes spread on the root element.

Classes​

ClassCapabilityDefaultDescription
.smSize-Small.
.mdSizeYesMedium.
.lgSize-Large.

Attributes​

AttributeSet byRequiredDescription
data-textarea-autoresizeConsumer-Grows the field to fit its content.
data-textarea-counterConsumer-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-invalid and 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.js layers in two independent, opt-in behaviors. Set use_autoresize: true (or add data-textarea-autoresize directly 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. Set has_counter: true (or add data-textarea-counter="<id>" directly, pointing at a .textarea-counter element - a bare data-textarea-counter falls back to a sibling .textarea-counter) to show a live "used / total" count read from the maxlength attribute and updated as the user types.