Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The field-sizing property

Reference for the CSS field-sizing property: make inputs and textareas grow to fit what the user types, with no JavaScript. Values, example and browser support.

Form controls such as <textarea> and <input> normally have a fixed size, however much text they hold. The field-sizing property changes that: with field-sizing: content, the control resizes to fit its content as the user types. Auto-growing textareas no longer need JavaScript.

CSS
textarea {
  field-sizing: content;
  min-height: 3lh;
  max-height: 10lh;
}

Try it

A textarea that grows

In a supporting browser, adding lines to the second box makes it taller (up to six lines), and typing in the input widens it. Elsewhere, both controls stay at their default size.

Syntax

CSS
field-sizing: fixed | content
  • Initial value: fixed
  • Applies to: elements with default preferred size, such as form controls
  • Inherited: no
  • Animatable: no (discrete)
  • Computed value: as specified

Values

Value Description
fixed The control uses its usual default size, based on attributes like size, cols and rows.
content The control's size follows its content (or its placeholder when empty). The size, cols and rows attributes are ignored.

Usage notes

  • Set limits. An unbounded control can get huge. Use min-width, max-width, min-height and max-height (the lh unit is handy for line counts).
  • Select elements. A <select> sized by content matches the width of its currently selected option, so it may change width when the choice changes.
  • Works without scripts, so it is a good progressive enhancement: unsupported browsers simply keep the fixed size.
  • Not just text. It also applies to number, date and other input types, where the size follows the displayed value.
  • Block layout. Inputs are inline-block by default; in flex or grid containers they may stretch, so set align-self or width: auto if the growth is not visible.

Browser support

Limited: it is supported in Chromium-based browsers, but not across all major browsers, so it is not yet part of Baseline. Use it as an enhancement and check current support tables.