Can a textarea finally size itself?
The new field-sizing property gives us a CSS-only way to make form controls such as <textarea> grow with their content. Instead of measuring scrollHeight in JavaScript, the browser layout engine handles most content changes directly.

That does not mean every framework scenario is automatically covered. Programmatic value updates, asynchronous component re-renders, and custom form libraries still deserve real-browser testing. But for normal typing, paste, undo/redo, and wrapping changes, the native version is refreshingly small.

What field-sizing: content does
Apply it to a textarea and give the control sensible minimum and maximum constraints:
textarea {
field-sizing: content;
rows: 3;
min-height: 5.5rem;
max-height: 20rem;
overflow: auto;
resize: vertical;
box-sizing: border-box;
}
The rows attribute and min-height provide the starting size. The textarea grows as lines are added, stops at max-height, and then becomes scrollable because overflow: auto remains available.
Keep resize: vertical unless your design truly forbids manual resizing. It lets users make the field larger if the constrained height does not fit their working style.
Browser support in 2026
Support is still relatively fresh, so check your audience before shipping CSS only.
- MDN lists
field-sizingbehindfield-sizing: contentas supported in Chrome 123 (March 2024), Edge 123 (March 2024), and Safari 18.0 (September 2024, with compatibility notes around some control types). - Can I Use tracks the same Chromium 123 and Safari 18 baseline; Firefox support should be verified against its current entry because support details can change between releases.
Because support is not universal, use feature detection rather than browser sniffing:
CSS.supports('field-sizing', 'content')
Native CSS vs the traditional JavaScript approach
| Concern | Native field-sizing |
Traditional JavaScript |
|---|---|---|
| Event listening | Usually none for normal content changes | Needs input, often change and framework hooks |
scrollHeight measurement |
Not required | Reset height, read scrollHeight, then set height |
| Typing and paste | Handled by the browser layout engine | input covers keyboard entry and paste in modern browsers |
| Undo/redo | Generally handled with native editing | Usually covered by input, but verify in custom components |
| Font loading | Layout responds when fonts change | Should recalculate after document.fonts.ready |
| Responsive width | Browser reflows as wrapping changes | Must listen to resize, ResizeObserver, or container changes |
| Maximum height | Use max-height |
Parse or compare against max-height; switch to scrolling |
| Manual resize | resize: vertical works naturally |
Inline height styles can fight the user’s manual resize |
| Maintenance cost | Low, but requires progressive enhancement | Higher: more events, layout reads, and edge cases |
The production fallback
The fallback below initializes only where native field-sizing is unavailable. It updates on input, after load, after fonts finish loading, and when the window or a container changes width. It respects the computed max-height, switches to scrolling only when needed, and clears the inline height at the cap so manual vertical resizing keeps working.
HTML
<div class="field">
<label for="note">Release notes</label>
<textarea
id="note"
name="note"
rows="3"
placeholder="Write the release notes..."
></textarea>
<div class="help" data-resize-status></div>
</div>
CSS
.field {
container-type: inline-size;
}
textarea {
width: 100%;
margin: 0;
padding: 0.75rem 0.875rem;
border: 1px solid #8a8f98;
border-radius: 0.75rem;
font: inherit;
line-height: 1.5;
box-sizing: border-box;
overflow: auto;
resize: vertical;
min-height: 5.5rem;
max-height: 20rem;
}
textarea:focus-visible {
outline: 3px solid #6ea8fe;
outline-offset: 2px;
}
@supports (field-sizing: content) {
textarea {
field-sizing: content;
}
[data-resize-status] {
display: none;
}
}
JavaScript
(function () {
'use strict';
if (
window.CSS &&
CSS.supports &&
CSS.supports('field-sizing', 'content')
) {
return;
}
var textareas = document.querySelectorAll('textarea[data-autosize]');
if (!textareas.length || !document.documentElement.attachShadow) {
return;
}
function getMaxHeight(textarea) {
var value = getComputedStyle(textarea).maxHeight;
var pixels = parseFloat(value);
return isFinite(pixels) ? pixels : Infinity;
}
function resizeTextarea(textarea) {
var maxHeight = getMaxHeight(textarea);
textarea.style.height = 'auto';
var nextHeight = textarea.scrollHeight;
var reachedMax = nextHeight >= maxHeight;
if (reachedMax) {
textarea.style.height = '';
textarea.style.overflowY = 'auto';
} else {
textarea.style.height = nextHeight + 'px';
textarea.style.overflowY = 'hidden';
}
}
function refreshAll() {
textareas.forEach(resizeTextarea);
}
textareas.forEach(function (textarea) {
textarea.setAttribute('data-autosize-fallback', '');
textarea.addEventListener('input', function () {
resizeTextarea(textarea);
});
});
window.addEventListener('load', refreshAll);
if (document.fonts && document.fonts.ready) {
document.fonts.ready.then(refreshAll);
}
window.addEventListener('resize', refreshAll);
if ('ResizeObserver' in window) {
var observer = new ResizeObserver(function (entries) {
entries.forEach(function (entry) {
var textarea = entry.target.querySelector('textarea[data-autosize]');
if (textarea) {
resizeTextarea(textarea);
}
});
});
textareas.forEach(function (textarea) {
var wrapper = textarea.closest('.field');
if (wrapper) {
observer.observe(wrapper);
}
});
}
refreshAll();
})();
Add data-autosize to each textarea that should use the fallback. The height: auto reset is important: without it, scrollHeight can reflect the old constrained height instead of the full content height.
Clearing the inline height at the maximum avoids a subtle bug. If JavaScript keeps writing an inline pixel height, it can override a user’s manual drag resize. Letting the CSS max-height take over keeps scrolling and manual resizing more predictable.
Framework and dynamic-form notes
If React, Vue, Svelte, or another component sets a value programmatically, call the same resize calculation after the update is reflected in the DOM. Native field-sizing handles ordinary editing very well, but I would still test controlled components, reset buttons, placeholders that change after localization loads, and content inserted by test utilities.
For dynamically added textareas, run the initializer again or use a shared resizeTextarea(element) function from your component’s update lifecycle. A single delegated input listener on the document can also reduce setup work.
Accessibility details
- Associate every textarea with a
<label for>. Do not rely on placeholder text alone. - Keep normal keyboard behavior intact. Auto-growth should not move focus or intercept typing.
- Use a visible
:focus-visiblestyle with enough contrast. - Avoid
resize: noneunless user research supports it; manual resizing helps people paste large notes. - Once
max-heightis reached, keepoverflow: autoso keyboard and screen-reader users can still reach all content. - Test browser zoom and long unbroken strings, not just short sentences.
Final take
field-sizing: content removes much of the scroll-height bookkeeping that used to belong in JavaScript. Use it with rows, min-height, max-height, resize: vertical, and overflow: auto. Then ship the feature-detected fallback above for browsers that still need the older approach.