# Textarea grow

Subtle web animation sketch from [https://mighil.com/animations](https://mighil.com/animations).

- **Live demo:** https://mighil.com/animations/textarea-grow
- **Standalone HTML:** https://mighil.com/animations/textarea-grow?download=1
- **This file:** https://mighil.com/animations/textarea-grow/textarea-grow.md
- **Technique:** `compose`

## What it does

Grows with your text and keeps it until Reset. Survives reload too.

## Instructions for AI / coding agents

Implement this micro-interaction in the user's stack (vanilla HTML, React, Vue, Svelte, etc.).

1. Use the **HTML** as the DOM structure (adapt JSX/templates as needed; keep class names and ids).
2. Include the **Theme** CSS (or map the same variables into the host design system). It switches light/dark with `prefers-color-scheme`.
3. Apply the **CSS** as-is when possible. It uses `var(--text-color)`, `var(--heading-color)`, `var(--background-color)`, etc. from the theme so both modes work.
4. Run the **JavaScript** after the markup mounts. Prefer `DOMContentLoaded` or a framework `useEffect` / `onMount`.
5. Keep motion respectful of `prefers-reduced-motion` if the snippet already checks it.
6. Do not depend on mighil.com runtime or fonts. Theme variables are enough for color.
7. If porting to a component, expose the interactive root via a ref and preserve accessibility attributes (`aria-*`, `role`, `button` types).

## Theme (auto light / dark)

```css
/* Auto light / dark — follows prefers-color-scheme */
:root{
  color-scheme: light dark;
  --text-color: hsl(0, 0%, 18%);
  --heading-color: hsl(0, 0%, 18%);
  --background-color: hsl(0, 0%, 99%);
  --bg-color: hsl(0, 0%, 99%);
  --link-color: hsl(0, 0%, 18%);
  --visited-color: hsl(0, 0%, 18%);
  --blockquote-color: hsl(0, 0%, 18%);
  --code-bg-color: hsl(0, 0%, 95%);
  --code-color: hsl(0, 0%, 18%);
  --sub-color: hsl(0, 0%, 29%);
}
@media (prefers-color-scheme: dark){
:root{
  --text-color: hsl(35, 25%, 85%);
  --heading-color: hsl(35.2, 32.6%, 82.5%);
  --background-color: hsl(60, 2.2%, 8.8%);
  --bg-color: hsl(60, 2.2%, 8.8%);
  --link-color: hsl(34.7, 55.3%, 79.8%);
  --visited-color: hsla(34.7, 55.3%, 79.8%, 0.85);
  --blockquote-color: hsl(35, 30%, 75%);
  --code-bg-color: hsl(30, 5%, 7.8%);
  --code-color: limegreen;
  --sub-color: hsla(34.7, 24.7%, 84.9%, 0.78);
}
}
```

## HTML

```html
<textarea class="grow-area" id="grow-area" rows="1" placeholder="Write a note…" aria-label="Growing note"></textarea>
```

## CSS

```css
.grow-area{
  width:min(100%,300px);box-sizing:border-box;min-height:40px;max-height:120px;padding:10px 12px;border-radius:8px;
  font:inherit;font-size:.9rem;line-height:1.4;color:inherit;resize:none;outline:none;overflow-y:hidden;
  border:1px solid color-mix(in srgb,var(--text-color) 14%,transparent);background:transparent;
  transition:border-color .2s ease, box-shadow .2s ease;
}

.grow-area.is-tall{overflow-y:auto}

.grow-area:focus{border-color:color-mix(in srgb,var(--text-color) 40%,transparent);box-shadow:0 0 0 3px color-mix(in srgb,var(--text-color) 8%,transparent)}
```

## JavaScript

```js
// Textarea grow — expands with content, persists until Reset (incl. reload)
  const growArea = document.getElementById('grow-area');
  const GROW_MIN = 40;
  const GROW_MAX = 120;
  const GROW_KEY = 'anim-grow-area';
  let growH = GROW_MIN;

document.querySelectorAll('[data-act]').forEach((btn) => {
    btn.addEventListener('click', (e) => {
      e.stopPropagation();
      const act = btn.getAttribute('data-act');
      if (act === 'grow') resetGrow();
    });
  });
```

---

_Source: https://mighil.com/animations/textarea-grow_
