CSS Auto-Resize Textarea

A textarea that grows with its content using field-sizing: content, capped at a max height, with no JavaScript.

  • textarea
  • auto grow
  • field-sizing
  • comment box
  • message
  • resize
HTML
<label class="grow-area">
  <span>Your message</span>
  <textarea name="message" rows="2" placeholder="Type a few lines and watch me grow…"></textarea>
</label>
CSS
.grow-area {
  display: grid;
  gap: 6px;
  width: 260px;
  color: #0c4a6e;
  font: 600 13px system-ui, sans-serif;
}

.grow-area textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 3lh;
  max-height: 8lh;
  padding: 10px 12px;
  border: 1.5px solid #bae6fd;
  border-radius: 12px;
  background: #fff;
  color: #0f172a;
  font: 400 15px/1.5 system-ui, sans-serif;
  resize: vertical;
  field-sizing: content;
}

.grow-area textarea:focus-visible {
  border-color: #0284c7;
  outline: none;
  box-shadow: 0 0 0 4px rgba(2, 132, 199, 0.15);
}

@supports (field-sizing: content) {
  .grow-area textarea {
    resize: none;
  }
}

About this CSS Auto-Resize Textarea

This CSS Auto-Resize Textarea is 34 lines of pure CSS (0.6 KB) with no JavaScript and no dependencies. It uses field-sizing, box shadows, CSS Grid and keyboard focus styles. It relies on field-sizing, which not every browser supports yet, so check the browser notes below. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #0c4a6e
  • #bae6fd
  • #fff
  • #0f172a
  • #0284c7

How to use this auto-resize textarea

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .grow-area class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback