Skip to content

Textarea

The same look and states as Input, for answers longer than one line.

data-stateUsed for
(omitted)Normal state
invalidValidation has failed
successThe content is confirmed valid

data-state is colour. Screen readers need aria-invalid="true" as well, or Field, which sets both.

ClassWhat it is
.lt-textareaThe field. The state comes from data-state.
VariableDefault
--lt-textarea-min-heightcalc(var(--lt-spacing-4) * 5)
--lt-textarea-paddingvar(--lt-spacing-2) var(--lt-spacing-3)
--lt-textarea-radiusvar(--lt-spacing-1)

--lt-textarea-min-height is a minimum height, not a fixed height. rows works above it, and the user can still drag the field taller. With the default font and padding the minimum height is a little under three rows, so rows="1" and rows="2" give the same field, and only rows="3" is taller. If rows alone should decide the height, set --lt-textarea-min-height: 0. The width is locked, since the class sets resize: vertical.

See Customising for how the variables and the layer work.

  • Every field needs a visible <label> with for pointing to the id.
  • If the field has an upper limit, say so in the help text before the user types. maxlength alone blocks typing without explaining why.
  • If you use a character counter, put it in an element with aria-live="polite" and let it announce only when the limit is near. Otherwise it interrupts the reading on every keystroke.
  • Do not turn off resize. It is often the only way the user gets an overview of a long text.