Delete Your Auto-Resize Textarea Script: field-sizing: content
October 7, 2026 | 7 min read | CSS
By Syed · Frontend Engineer & Creator of UITweak
You know the script. On every keystroke it sets the textarea height to auto, reads scrollHeight, and writes it back. It mostly works, until the webfont loads late and every line re-wraps, or a saved draft renders server-side at the wrong height and the client corrects it with a visible jump. It is layout work done in JavaScript, on the main thread, per keystroke, and the browser has been able to do it natively since field-sizing: content went Baseline in June 2026. One declaration, and the textarea sizes itself at layout time.
30-second version: field-sizing: content makes a textarea or input shrink-wrap its content and grow as the user types. Baseline since June 2026 (Chrome 123, Safari 26.2, Firefox 152). Pair it with min-height in lh units and a max-height, and gate your old script behind CSS.supports instead of deleting it outright.
Recipe 1: The One-Line Textarea (With Clamps)
The property alone is enough to grow, but a bare field-sizing: content is not shippable: an empty textarea collapses toward one line, and a pasted essay grows without bound. The production pattern is three declarations:
textarea.autogrow {
field-sizing: content;
min-height: 3lh; /* floor: never smaller than 3 lines */
max-height: 12lh; /* ceiling: then it scrolls */
overflow-y: auto;
}lh is the line-height unit, so the floor and ceiling scale with the font instead of being magic pixel numbers. Past the ceiling the textarea gets its scrollbar back, which is exactly what you want: a comment box should not shove the submit button off the screen because someone pasted a novel.
The rows Gotcha (Read This Before You Ship)
Under field-sizing: content, the rows attribute is ignored. The browser sizes from content, not from the attribute, so <textarea rows="4"> renders at content height and your four-row default silently disappears. This is the number-one migration bug, and it is invisible until someone opens the form. The fix is the min-height floor from Recipe 1: it replaces rows as the empty-state size, and unlike rows it keeps working if you later change the font.
Recipe 2: Inputs That Grow Too
It is not textarea-only. Text inputs shrink-wrap their content as well, which finally kills the fixed-width search box that is either comically wide or always too short:
.search-input {
field-sizing: content;
min-inline-size: 12ch; /* without this: cursor-width collapse */
max-inline-size: 100%;
}The minimum is load-bearing here. With no content and no minimum, the input shrinks to roughly the width of the text cursor. 12ch gives it a sane resting size while still letting it grow, andmax-inline-size: 100% keeps it inside its container on narrow screens. Note that maxlength naturally caps the growth too, since the content cannot exceed it.
Recipe 3: Retire the Old Script Safely
Do not delete the script on day one. Gate it: run the native path where supported, keep the old listener as the fallback for older browsers. This is exactly what Logseq did when they adopted it, and the pattern is three lines:
// only attach the scrollHeight hack where the CSS is missing
if (!CSS.supports("field-sizing", "content")) {
document.querySelectorAll("textarea.autogrow").forEach(attachAutoGrow);
}In unsupported browsers nothing about your CSS breaks: the declarations are ignored and the user gets a normal fixed textarea with a scrollbar, while your old script takes over. That is the whole migration. No flag day, no user-agent sniffing, and the fallback deletes itself from your bundle the day you drop those browsers.
Stuck in a grid? If a field-sizing textarea inside a grid or flex container refuses to shrink, the container is stretching it. Add align-self: start (or justify-self: start) to the textarea so the content sizing wins over the stretch. This is the most common "it does not work" report, and it is a container problem, not a property problem. For layout experiments around it, our free Tailwind Grid Builder lets you prototype the container behavior live before you commit to the CSS.
Quick Recap
field-sizing: contentgrows textareas and inputs with their content at layout time. No keystroke listeners.- Always ship it with a
min-heightinlh(therowsattribute is ignored) and amax-heightwithoverflow-y: auto. - Inputs need
min-inline-sizeor they collapse to cursor width when empty. - Migrate with
CSS.supports("field-sizing", "content"): native path where available, old script as fallback. - Grid or flex container stretching your field?
align-self: starthands sizing back to the content.
Contenteditable Is Not the Alternative
Before field-sizing existed, the other way to get a growing text field was a contenteditable div. I have inherited codebases built on that hack and I would not choose it again. A contenteditable div is not a form control: it submits nothing, so you end up reading innerText with JavaScript and copying it into a hidden input on submit. Screen readers announce it inconsistently. Spellcheck, autocorrect, and password-manager behavior differ from a real textarea in every browser. Paste rich text and you inherit inline styles you then have to strip. field-sizing keeps the actual textarea, so form submission, built-in validation, autocomplete, and assistive-tech behavior stay exactly as the browser built them. One declaration buys the growth without surrendering the control.
The Chat-Composer Problem: Growing Fields in Flex Rows
The place field-sizing bites in real layouts is the chat composer: a textarea and a send button in a flex row. The row defaults to align-items: stretch, so as the textarea grows the button stretches into a tall slab. Set align-items: end on the row and the button pins to the bottom while the field grows upward past it. The same class of bug shows up anywhere a growing field shares a row with fixed siblings: toolbars, comment boxes, search bars with a submit button. I check the alignment on the row before I blame the property. In practice the property is fine; the flex container is doing exactly what it was told.
.composer {
display: flex;
align-items: end; /* button pins to the bottom as the field grows */
gap: 0.5rem;
}
.composer textarea {
field-sizing: content;
min-height: 2.5lh;
max-height: 8lh;
overflow-y: auto;
flex: 1;
}Long URLs and Unbroken Strings
field-sizing grows the block axis as lines wrap. A two-hundred-character URL with no spaces never wraps, so the textarea gains no height from it while the URL overflows sideways. Add overflow-wrap: anywhere so long tokens break and the growth tracks reality. And check the wrap attribute: with wrap="off" the textarea never wraps at all, so content sizing grows it horizontally instead of vertically. If your textarea suddenly gets wide instead of tall, wrap="off" is the first thing to check. I have seen this exact confusion filed as a browser bug twice. It was the attribute both times.
Debugging Checklist: Property Present, Nothing Happening
When field-sizing seems ignored, work this list. First, the declaration must sit on the control itself, not a wrapper div. The property only affects form controls; on a plain div it does nothing. Second, confirm there is no wrap="off" forcing horizontal growth. Third, replace any rows attribute with a min-height floor, since rows is ignored under content sizing. Fourth, open DevTools and read the computed value: if field-sizing computes to content and the height still will not move, an ancestor is stretching the field, and align-self: start on the control hands sizing back to the content. Four checks, five minutes, and the mystery is always one of them.
Frequently Asked Questions
Which browsers support it?
Baseline newly available since June 16, 2026: Chrome and Edge 123 (March 2024), Safari 26.2 (December 2025), Firefox 152 (June 2026, the last engine). Older browsers ignore it and render a normal fixed control, which makes it safe progressive enhancement.
Does it work on select and file inputs?
Yes, with per-control behavior. A dropdown sizes to the currently selected option instead of the longest one, a listbox expands to show all options without a scrollbar, and a file input fits the current filename. The textarea case is the one most teams adopt first. For styling the select dropdown itself, beyond just its size, see our base-select styling guide.
Does the height animate as it grows?
No. The size change happens at layout time, so it is instant, not transitioned. In practice nobody misses the animation: the growth tracks the caret, which is already moving. If you truly need animated expansion, that is a separate problem (and a separate article).
What about server-rendered drafts?
This is where the CSS version wins outright. The old script measured after hydration, so a saved draft flashed at the wrong height. With field-sizing the correct height is computed during layout, before first paint. No measurement code, no hydration mismatch, no jump.