Pure TailwindMIT licensed

Tailwind Auto-Grow Textarea

A textarea that grows with its content and shrinks back — one utility, field-sizing-content, replacing the ResizeObserver-and-hidden-mirror dance every form library used to ship.

Live Demo
Plain CSSTailwind v4
Try it

Untitled UI Pro: 5,000+ React + Tailwind CSS v4 components · from $349 one-time

Untitled UI React · Affiliate link

Get Untitled UI Pro

The code

<div class="tif-22 grid min-h-svh w-full place-items-center bg-tif22-bg px-6 py-14 font-tif22-sans" aria-label="Auto-grow textarea demo">
  <label class="grid w-full max-w-80 gap-1.5">
    <span class="font-tif22-mono text-[10px] tracking-[0.12em] text-tif22-mut uppercase">Notes</span>
    <textarea name="tif22-notes" rows="2" placeholder="Type as much as you need…"
      class="field-sizing-content max-h-60 min-h-16 w-full resize-none overflow-y-auto rounded-[10px] border border-white/12 bg-tif22-field px-3.5 py-3 text-sm font-medium leading-relaxed text-tif22-ink outline-none transition-[border-color,background-color] duration-200 placeholder:text-tif22-mut focus:border-tif22-acc focus:bg-tif22-field2"></textarea>
    <span class="text-[11px] text-tif22-mut">Field grows as you type</span>
  </label>
</div>
@import "tailwindcss";

@theme {
  --color-tif22-bg: #12121a;
  --color-tif22-bg: oklch(0.19 0.015 285);
  --color-tif22-field: #1a1a22;
  --color-tif22-field: oklch(0.23 0.015 285);
  --color-tif22-field2: #1f1f2a;
  --color-tif22-field2: oklch(0.26 0.018 285);
  --color-tif22-ink: #f0eeff;
  --color-tif22-ink: oklch(0.95 0.02 290);
  --color-tif22-mut: #b8b6d4;
  --color-tif22-mut: oklch(0.77 0.03 290);
  --color-tif22-acc: #a78bfa;
  --color-tif22-acc: oklch(0.74 0.15 295);
  --font-tif22-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-tif22-mono: 'JetBrains Mono', ui-monospace, monospace;
}

.tif-22 {
  width: 100%;
}

.tif-22 ::selection {
  background: var(--color-tif22-acc);
  color: #12121a;
}

Setup — do this once per project

Skip this if your project already runs Tailwind v4.

1Load Tailwind
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

Compiles in the browser — perfect for a CodePen or a quick test, not for production.

2Add the stylesheetRequiredthe @theme block is what makes the custom utilities exist
@import "tailwindcss";

@theme {
  --color-tif22-bg: #12121a;
  --color-tif22-bg: oklch(0.19 0.015 285);
  --color-tif22-field: #1a1a22;
  --color-tif22-field: oklch(0.23 0.015 285);
  --color-tif22-field2: #1f1f2a;
  --color-tif22-field2: oklch(0.26 0.018 285);
  --color-tif22-ink: #f0eeff;
  --color-tif22-ink: oklch(0.95 0.02 290);
  --color-tif22-mut: #b8b6d4;
  --color-tif22-mut: oklch(0.77 0.03 290);
  --color-tif22-acc: #a78bfa;
  --color-tif22-acc: oklch(0.74 0.15 295);
  --font-tif22-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-tif22-mono: 'JetBrains Mono', ui-monospace, monospace;
}

.tif-22 {
  width: 100%;
}

.tif-22 ::selection {
  background: var(--color-tif22-acc);
  color: #12121a;
}
3Fonts used by this demooptional — skip if you have your own type stack
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Plus+Jakarta+Sans:wght@400;500;600&display=swap">

What changed in the port

Which parts became utilities, which stayed CSS, and why.

  • field-sizing: content has a first-class utility in v4 — the port is shorter than the original stylesheet by about thirty lines.
  • A max-h-60 ceiling was added; the CSS original mentions it only as a customisation, and without it a long paste is a layout bug.
  • Everything else — padding, radius, focus tint — is the same vocabulary as every other field here, which is the argument for utilities in one sentence.
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS demo from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Tailwind Auto-Grow Textarea
Source: https://codefronts.com/components/tailwind-css-input-fields/tailwind-auto-grow-textarea/

A textarea that grows with its content and shrinks back — one utility, field-sizing-content, replacing the ResizeObserver-and-hidden-mirror dance every form library used to ship.
## HTML
```html
<div class="tif-22 grid min-h-svh w-full place-items-center bg-tif22-bg px-6 py-14 font-tif22-sans" aria-label="Auto-grow textarea demo">
  <label class="grid w-full max-w-80 gap-1.5">
    <span class="font-tif22-mono text-[10px] tracking-[0.12em] text-tif22-mut uppercase">Notes</span>
    <textarea name="tif22-notes" rows="2" placeholder="Type as much as you need…"
      class="field-sizing-content max-h-60 min-h-16 w-full resize-none overflow-y-auto rounded-[10px] border border-white/12 bg-tif22-field px-3.5 py-3 text-sm font-medium leading-relaxed text-tif22-ink outline-none transition-[border-color,background-color] duration-200 placeholder:text-tif22-mut focus:border-tif22-acc focus:bg-tif22-field2"></textarea>
    <span class="text-[11px] text-tif22-mut">Field grows as you type</span>
  </label>
</div>
```
## CSS
```css
@import "tailwindcss";

@theme {
  --color-tif22-bg: #12121a;
  --color-tif22-bg: oklch(0.19 0.015 285);
  --color-tif22-field: #1a1a22;
  --color-tif22-field: oklch(0.23 0.015 285);
  --color-tif22-field2: #1f1f2a;
  --color-tif22-field2: oklch(0.26 0.018 285);
  --color-tif22-ink: #f0eeff;
  --color-tif22-ink: oklch(0.95 0.02 290);
  --color-tif22-mut: #b8b6d4;
  --color-tif22-mut: oklch(0.77 0.03 290);
  --color-tif22-acc: #a78bfa;
  --color-tif22-acc: oklch(0.74 0.15 295);
  --font-tif22-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-tif22-mono: 'JetBrains Mono', ui-monospace, monospace;
}

.tif-22 {
  width: 100%;
}

.tif-22 ::selection {
  background: var(--color-tif22-acc);
  color: #12121a;
}
```

How this works

One declaration, whole feature. field-sizing: content tells the browser to size the box to its text instead of the rows attribute:

class="field-sizing-content min-h-16 max-h-60 resize-none overflow-y-auto"

Bounds are still yours. The property takes only content or fixed, so a floor and a ceiling are ordinary min-h-*/max-h-* — without the ceiling a long paste pushes your submit button off the screen.

Make it yours

  • Ceiling: max-h-60, paired with overflow-y-auto so long input scrolls.
  • Resting size: min-h-16 or the rows attribute — both act as a floor.
  • Accent: --color-tif22-acc on focus.
  • Rhythm: leading-relaxed gives each new line more room to arrive into.

Gotchas — read before shipping

  • Chrome 123+, Safari 26+, Firefox 137+. Older browsers sit at rows=&quot;2&quot; — a graceful fallback, but not auto-grow.
  • Growth shifts everything below it. Put the textarea in a grid or flex container that tolerates height changes.
  • resize-none removes the manual grip; if support is missing, the user now has neither growth nor a grip. Keep rows generous.

Browser support

ChromeSafariFirefoxEdge
123+26+137+123+

field-sizing is newly Baseline-ish; below these versions the textarea is a normal fixed-rows field.

Techniques used in this demo

Utilitiesfirst-class utility or variant

Theme tokensset in @theme, used by a utility

Search CodeFronts

Loading…