Entry 08
Textarea that grows with its content
Use it for any multi-line input, such as a chat composer or a comment box. field-sizing: content sizes the textarea to its text, so there is no auto-grow script and no hidden mirror element.
Code
textarea {
field-sizing: content;
min-height: 3lh;
max-height: 12lh;
resize: none;
}The height snaps to each new line. To animate it, wrap the textarea and let a ResizeObserver copy its height onto the wrapper. The wrapper transitions.
<div class="field"><textarea></textarea></div>.field {
box-sizing: content-box;
overflow: clip;
}
@media (prefers-reduced-motion: no-preference) {
.field { transition: height 0.2s var(--ease-out, ease-out); }
}const textarea = document.querySelector(".field textarea");
new ResizeObserver(([entry]) => {
textarea.parentElement.style.height = `${entry.borderBoxSize[0].blockSize}px`;
}).observe(textarea);Why it works, the rules and the credits
Why it works
- The browser measures the text itself, so the size is right on first paint, on paste and on window resize.
- The textarea reaches its final height at once. Only the wrapper animates, and it clips the textarea until it catches up.
lhis one line at the element's own line-height.min-height: 3lhmeans three lines at any font size.
Rules
- Bound it with
min-heightandmax-height. A fixedheightbrings the fixed size back. Pastmax-heightthe textarea scrolls. - Put the border and background on the wrapper and leave the textarea bare. The box the user sees must be the one that animates.
- Keep the wrapper
content-box. The observer writes the textarea's full height, and aborder-boxwrapper would subtract its own border from it. - Write no fallback. A browser without
field-sizingshows a fixed textarea that scrolls.
Support
- Chrome
- 123
- Firefox
- 152
- Safari
- 26.2
Baseline newly available since June 2026.
Credits
Borrowed from: Jhey Tompkins, @jh3yy on X, 2026-10-01
Docs: MDN: field-sizing · Adam Argyle, CSS field-sizing · MDN: ResizeObserver