The CSS field-sizing property lets form controls — <textarea>, <input>, <select> — size themselves to their content instead of their UA-defined default box. Set field-sizing: content and a textarea grows as the user types, replacing the classic scrollHeight JavaScript hack. Build your rule below and watch a live preview.
content sizes the control to fit text. fixed restores the UA default (rows/cols/size attributes). Flip back and forth to compare.ch and lh units track the form control's own font.@supports (field-sizing: content) isolates the rule so unsupported browsers fall back to their normal sizing.
Support: field-sizing shipped in Chrome 123 / Edge 123 (March 2024) and Safari 17.4. Firefox is implementing it behind a flag. Older browsers ignore the declaration and fall back to rows/cols/size attributes. Use @supports (field-sizing: content) to be safe.
scrollHeight hack. The classic JS pattern (el.style.height = 'auto'; el.style.height = el.scrollHeight + 'px') thrashes layout and breaks on paste. field-sizing: content does it intrinsically.<select> too. Selects with long options finally stop overflowing their container; the dropdown shrinks back when a shorter option is picked.min-* and max-*. An empty textarea with field-sizing: content can collapse to zero height — min-height: 2lh keeps it usable.ch and lh units pair perfectly. They scale with the form control's font, so a 40-character textarea stays ~40 characters wide whether the font is 14px or 24px.resize. Users can still drag the corner to override; field-sizing only sets the intrinsic preferred size.