Updated: How to auto-resize a textarea (or other inputs) in pure CSS

Posted . Visible to the public. Auto-destruct in 60 days

field-sizing: content is now baseline.

Changes

  • Modern CSS offers the [field-sizing](https://developer.mozilla.org/en-US/docs/Web/CSS/field-sizing) property to allow elements to automatically adjust size (width and/or height) to fit their contents.
  • The most common use case are textareas which start fairly small (e.g. 2 or 3 rows tall) but grow when users enter longer text.
  • ## Usage
  • ```css
  • textarea {
  • field-sizing: content;
  • }
  • ```
  • -That's it! At least in modern Chromium-based browsers.
  • +That's it!
  • -> [NOTE "Limited browser support"]
  • -> Support is still lacking in Firefox and Safari (as of mid 2025). If you want auto-sizing inputs in those browsers, you still need a JavaScript solution.
  • +## Browser Support
  • -## Suggested usage
  • +Since June 2026 this is [supported in all browsers](https://caniuse.com/wf-field-sizing) and part of Baseline 2026.
  • -I suggest using a small JavaScript library like [autosize](https://github.com/jackmoore/autosize) for browsers that do not support `field-sizing` yet.
  • +* Chrome/Edge 123 (March 2024)
  • +* Safari 26.2 (November 2025)
  • +* Firefox 152 (June 2026)
  • +
  • +
  • +
  • +## Suggested legacy solution
  • +
  • +If you need to support legacy browsers, I suggest using a small JavaScript library like [autosize](https://github.com/jackmoore/autosize).
  • While at it, I also like to disable manual resizing.
  • ```css
  • @supports (field-sizing: content) {
  • textarea {
  • field-sizing: content;
  • resize: none;
  • }
  • }
  • ```
  • ```javascript
  • import autosize from 'autosize'
  • if (!CSS.supports('field-sizing', 'content')) {
  • autosize(element) // simplified; you also need `autosize.destroy` unless you're building an MPA.
  • }
  • ```
  • Note how we check for `field-sizing` support in both our CSS and JavaScript. We want neither solution to affect the other.
  • > [NOTE]
  • > Unlike `field-sizing`, any JavaScript auto-resizing library likely has issues with elements inside hidden containers or elements that are not yet attached to the DOM.
  • > When adding changes to your application that may cause such issues, be sure to check in browsers that don't support `field-sizing` if everything still works as expected.
Profile picture of Arne Hartherz
Arne Hartherz
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2026-11-13 12:56)