Browse docs

Auto-growing textarea

Textarea that grows to fit content via field-sizing. Zero JavaScript.

stableSince 0.2.0

On this page
  1. Semantic HTML
  2. Progressive enhancement
  3. Max height cap
ExampleScroll inside to see moreOpen in a new page

The .pl-c-textarea-auto grows to fit its content using field-sizing: content (Chrome 123+). No JavaScript auto-resize.

Semantic HTML

<textarea class="pl-c-textarea-auto" rows="2"></textarea>

Progressive enhancement

Where field-sizing: content is not supported, the textarea retains its rows attribute (fixed height).

Max height cap

Cap the growth with --pl-c-textarea-max-block:

<textarea
  class="pl-c-textarea-auto"
  style="--pl-c-textarea-max-block: 8rem;"
></textarea>

Beyond the cap, the textarea scrolls instead of growing.

Search Porchlight