# Textarea

> A textarea whose label folds up, whose height eases to fit the text, and whose ring fills as you near the limit, with the characters left in the last fifth.

Forms · textarea, form, counter, autosize · HTML, CSS, vanilla JS · no dependencies · updated 2026-10-21
Demo: https://kodza.dev/components/textarea/

## Files

The code below, served as files: byte for byte what the Kodza site copies (the CSS includes its theme guard).

- [`kodza-textarea.css`](https://kodza.dev/registry/textarea/kodza-textarea.css) · 11.9 KB
- [`kodza-textarea.js`](https://kodza.dev/registry/textarea/kodza-textarea.js) · 5.2 KB
- [`kodza-textarea.html`](https://kodza.dev/registry/textarea/kodza-textarea.html) · 1.1 KB · the markup, to adapt and paste into your page

**Can you run shell commands? Download the CSS and the JS, don't retype them.** Retyping costs thousands of tokens and can drop or change lines of the CSS. Put the files where your stack expects them (Use it says where: change the `-o` paths):

```bash
curl -fsSL --create-dirs -o kodza/kodza-textarea.css https://kodza.dev/registry/textarea/kodza-textarea.css
curl -fsSL --create-dirs -o kodza/kodza-textarea.js https://kodza.dev/registry/textarea/kodza-textarea.js
```

Then load the files from your page as Use it shows, instead of pasting the content. The HTML is the part you adapt (text, links, modifiers): paste it from the Code section. Copy the CSS and the JS from the Code section only if you can't run commands, exactly as they are. (Windows PowerShell: `curl.exe`.)

## API

- Root: `.kodza-textarea`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-textarea-bg: #ffffff`
  - `--kz-textarea-fg: #0a0a0a`
  - `--kz-textarea-muted: rgba(10, 10, 10, 0.6)`
  - `--kz-textarea-line: rgba(10, 10, 10, 0.14)`
  - `--kz-textarea-line-hover: rgba(10, 10, 10, 0.3)`
  - `--kz-textarea-soft: rgba(10, 10, 10, 0.06)`
  - `--kz-textarea-error: #0a0a0a`
  - `--kz-textarea-radius: 12px`
  - `--kz-textarea-pad: 16px`
  - `--kz-textarea-ease: cubic-bezier(0.22, 1, 0.36, 1)`
- Attributes:
  - `data-error` (e.g. `Ten characters at least. Bugs need context.`)
  - `data-max` (e.g. `280`)
- Lifecycle: `kodza:init` / `kodza:destroy` on `document`, with `{ detail: { root } }` to target a container.

## Dark mode

The values Kodza uses on a dark background (`#0a0a0a`). For a page that follows the system theme, add them after the component's CSS:

```css
@media (prefers-color-scheme: dark) {
  .kodza-textarea {
    --kz-textarea-bg: #161616;
    --kz-textarea-fg: #f2f2f0;
    --kz-textarea-muted: rgba(242, 242, 240, 0.62);
    --kz-textarea-line: rgba(255, 255, 255, 0.14);
    --kz-textarea-line-hover: rgba(255, 255, 255, 0.3);
    --kz-textarea-soft: rgba(255, 255, 255, 0.07);
    --kz-textarea-error: #f2f2f0;
  }
}
```

A site with its own theme switch puts the same rules under its dark selector instead (`[data-theme="dark"] .kodza-textarea { … }`); a single dark section, under that section's class.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-textarea.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-textarea.css">`. Without a shell, paste it in a `<style>` in `<head>` instead. It only touches `kodza-` classes.
- HTML: where the component goes. Paste it as many times as you need: instances never interfere.
- JS: `kodza/kodza-textarea.js`, loaded with `<script src="kodza/kodza-textarea.js" defer></script>` in `<head>`. Without a shell, paste it in a `<script>` before `</body>` (or in `<head>`: it waits for the page). One copy per page, whatever the number of instances.
- Restyle with the `--kz-…` variables, set on the component's root element itself (the root declares its own defaults, so a value on an ancestor is ignored), and with the modifiers / attributes listed under API.
- Font: it takes the page's own. The Kodza look is Geist: `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Content added later (AJAX navigation, a SPA route, a builder preview): start it with `document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: container } }))`; before removing it, the same call with `'kodza:destroy'` stops it and puts the original markup back.

### Claude artifact (claude.ai)

- Paste the CSS in a `<style>` and the JS in a `<script>` at the end, in the artifact itself: it loads stylesheets only from Google Fonts and scripts only from a few CDNs, so no `<link>` or `<script src>` to Kodza.
- Writing the artifact file with a shell? Insert the downloaded files (Files) with a command instead of retyping them: a line `KODZA-CSS` alone inside the `<style>`, `KODZA-JS` inside the `<script>`, then `sed -e '/^KODZA-CSS$/{r kodza/kodza-textarea.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-textarea.js' -e 'd' -e '}' page.html > artifact.html`.
- Font: load Geist from Google Fonts (allowed): `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Dark mode: the viewer sets `data-theme="dark"` or `"light"` on `<html>`, or nothing when it follows the system. Write the Dark mode rules twice: inside `@media (prefers-color-scheme: dark)` with `:root:not([data-theme="light"])` in front of each selector, and with `:root[data-theme="dark"]` in front of each selector.
- Forms: there is nowhere to send them. Handle `submit` in your script with `event.preventDefault()` and show the result in the page.

### WordPress

- HTML: a **Custom HTML** block (or a pattern / template part). WordPress keeps this markup as it is only for users allowed to post unfiltered HTML (Administrators; Super Admins on multisite): for anyone else it strips tags such as `<svg>`, `<input>` or `<dialog>`, so add it from the theme (a pattern or template part) instead.
- CSS and JS: the downloaded files go in the theme, under `wp-content/themes/<your-theme>/kodza/` (the child theme if there is one), enqueued from its functions.php (or a code-snippets plugin):
  ```php
  add_action('wp_enqueue_scripts', function () {
    $dir = get_stylesheet_directory() . '/kodza/';
    $uri = get_stylesheet_directory_uri() . '/kodza/';
    wp_enqueue_style('kodza-textarea', $uri . 'kodza-textarea.css', [], filemtime($dir . 'kodza-textarea.css'));
    wp_enqueue_script('kodza-textarea', $uri . 'kodza-textarea.js', [], filemtime($dir . 'kodza-textarea.js'), true);
  });
  ```
  Scoped to `kodza-` classes, the CSS never touches the theme. One copy of the JS, whatever the number of blocks.
- No access to the theme files? The CSS can also go, as it is, in **Appearance → Customize → Additional CSS** (classic theme) or **Styles → Additional CSS** in the Site Editor (block theme).
- Theme with AJAX page transitions: fire `kodza:init` on the new content after each swap (and `kodza:destroy` on the old one).
- Performance plugin (WP Rocket, LiteSpeed Cache, Perfmatters…) with **Delay JavaScript execution** turned on: add `kodza` to the scripts it must not delay. Otherwise the component waits for the visitor's first scroll, tap or mouse move, and that first click can be lost.
- Colours: by default, match the theme's palette. After the component's CSS, point these variables at the theme's colours, on the component root, Kodza's value as the fallback:
  `.kodza-textarea { --kz-textarea-fg: var(TEXT, #0a0a0a); --kz-textarea-bg: var(BACKGROUND, #ffffff); }`
  TEXT, BACKGROUND and ACCENT (the colour the theme fills its own buttons with) are the theme's own colour variables — block themes (theme.json, like Twenty Twenty-Five): `--wp--preset--color--contrast`, `--wp--preset--color--base`, `--wp--preset--color--contrast` (they fill their buttons with it; their accent-1… colours are decorative); Astra: `--ast-global-color-2`, `--ast-global-color-4`, `--ast-global-color-0`; Kadence: `--global-palette3`, `--global-palette9`, `--global-palette1`; GeneratePress: `--contrast`, `--base-3`, `--accent`; Blocksy: `--theme-palette-color-4`, `--theme-palette-color-8`, `--theme-palette-color-1`. Use only these names, and only if the site really has them (the theme's CSS, or Styles → Colors): the `--wp--preset--color--black`, `--white`, `--vivid-…` that WordPress adds everywhere are not the theme's palette. Another theme, or one without these variables (Hello Elementor, OceanWP): leave the variables alone, it keeps Kodza's monochrome; same when the developer asks for monochrome or the Kodza look. Leave the translucent greys (`rgba(10, 10, 10, …)`) as they are: they suit any light background. On a dark palette, set the other variables from Dark mode too.
- WordPress turns straight quotes and `--` into typographic ones in the text of a Custom HTML block (not inside `<code>` or `<pre>`).

#### With Elementor

- HTML: an **HTML** widget (Elementor shows it to administrators only). It keeps the code exactly as pasted, straight quotes included.
- CSS and JS: as above. Elementor's Site Settings → Theme Style styles every button, field, link and image of the page, components included; the theme guard at the end of the CSS keeps the component's buttons, fields and link colours as they are.
- The Elementor editor redraws each widget after the page has loaded: without the script below, the component stays still in the editor preview (the published page works). Add it once per site, in the footer like the component's script (`kodza/elementor-editor.js`, or a code-snippets plugin):

```js
// Kodza in the Elementor editor: the editor redraws each HTML widget after the page has loaded.
// Start Kodza in what it draws, stop it in what it replaces or removes. Once per site.
window.addEventListener('elementor/frontend/init', () => {
  if (!elementorFrontend.isEditMode()) return;
  class KodzaWidget extends elementorModules.frontend.handlers.Base {
    onInit() {
      super.onInit();
      this.kodza = [...this.$element[0].children];
      document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: this.$element[0] } }));
    }
    onDestroy() {
      super.onDestroy();
      this.kodza.forEach((root) => document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } })));
    }
  }
  elementorFrontend.elementsHandler.attachHandler('html', KodzaWidget);
});
```

- No child theme: everything can go in the HTML widget instead, `<style>` with the CSS, the HTML, then `<script>` with the JS. It works on the page and in the editor without the script above.

### Shopify

- Files: `assets/kodza-textarea.css` and `assets/kodza-textarea.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-textarea.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-textarea.js' | asset_url }}" defer></script>`, then the HTML.
- The theme editor re-renders sections: restart them with
  `document.addEventListener('shopify:section:load', (e) => document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: e.target } })));`
  and the same with `shopify:section:unload` → `kodza:destroy`.

### React / Next.js

- Files, side by side (e.g. in `components/kodza/`): `Textarea.tsx` (below), the CSS block under Code saved as `textarea.css` and the JS block as `textarea.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { Textarea } from '@/components/kodza/Textarea';` then `<Textarea />`. Props: `max` (`data-max`: "280"), `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-textarea-bg': … }}`), `className`, `style` and the other props of its `<div>` (`onClick`, `aria-…`).
- Next.js App Router: it is a Client Component already (`'use client'`). Pages Router: Next.js takes global CSS only in `pages/_app`, so move the `import './textarea.css'` line there.
- Safe under StrictMode, client-side navigation and prop changes: when a prop changes, the `key` gives React a fresh element, `kodza:destroy` stops the script on the old one and `kodza:init` starts it on the new one.

```tsx
'use client';
// Kodza — Textarea, for React. From https://kodza.dev/components/textarea/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: textarea.css and textarea.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './textarea.css';

export type TextareaProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars" | "max"> & {
  /** data-max on the root (default: 280) */
  max?: "280";
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #ffffff */
    "--kz-textarea-bg"?: string | number;
    /** default: #0a0a0a */
    "--kz-textarea-fg"?: string | number;
    /** default: rgba(10, 10, 10, 0.6) */
    "--kz-textarea-muted"?: string | number;
    /** default: rgba(10, 10, 10, 0.14) */
    "--kz-textarea-line"?: string | number;
    /** default: rgba(10, 10, 10, 0.3) */
    "--kz-textarea-line-hover"?: string | number;
    /** default: rgba(10, 10, 10, 0.06) */
    "--kz-textarea-soft"?: string | number;
    /** default: #0a0a0a */
    "--kz-textarea-error"?: string | number;
    /** default: 12px */
    "--kz-textarea-radius"?: string | number;
    /** default: 16px */
    "--kz-textarea-pad"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-textarea-ease"?: string | number;
  };
  className?: string;
};

export function Textarea({ max = "280", vars, className, style, ...rest }: TextareaProps) {
  const ref = useRef<ComponentRef<'div'>>(null);
  const classes = ["kodza-textarea", className].filter(Boolean).join(' ');
  // Everything the markup is made of: when it changes, React gets a fresh element (see the top)
  const key = JSON.stringify([classes, max, vars, style, rest]);

  // Starts the script on this element once React has rendered it, stops it when it goes
  useEffect(() => {
    const root = ref.current;
    let live = true;
    // @ts-ignore: a plain script, no types to find
    import('./textarea.js').then(() => {
      if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
    });
    return () => {
      live = false;
      document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
    };
  }, [key]);

  return (
    <div key={key} {...rest} className={classes} data-max={max} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <label className="kodza-textarea__box">
        <textarea className="kodza-textarea__input" name="message" rows={2} placeholder=" " maxLength={280} required minLength={10} data-error="Ten characters at least. Bugs need context." />
        {' '}
        <span className="kodza-textarea__label">What broke?</span>
      </label>
      <p className="kodza-textarea__foot">
        <span className="kodza-textarea__note">
          <span className="kodza-textarea__hint">Steps to reproduce are a love language.</span>
          <span className="kodza-textarea__error" aria-live="polite" />
        </span>
        {' '}
        <span className="kodza-textarea__count" aria-hidden="true">
          <svg viewBox="0 0 20 20">
            <circle className="kodza-textarea__ring-track" cx="10" cy="10" r="8" />
            <circle className="kodza-textarea__ring" cx="10" cy="10" r="8" pathLength="1" />
          </svg>
          <span className="kodza-textarea__left" />
        </span>
      </p>
    </div>
  );
}
```

## Code

```html
<div class="kodza-textarea" data-max="280">
  <label class="kodza-textarea__box">
    <textarea class="kodza-textarea__input" name="message" rows="2" placeholder=" " maxlength="280" required minlength="10" data-error="Ten characters at least. Bugs need context."></textarea>
    <span class="kodza-textarea__label">What broke?</span>
  </label>
  <p class="kodza-textarea__foot">
    <span class="kodza-textarea__note"><span class="kodza-textarea__hint">Steps to reproduce are a love language.</span><span class="kodza-textarea__error" aria-live="polite"></span></span>
    <span class="kodza-textarea__count" aria-hidden="true"><svg viewBox="0 0 20 20"><circle class="kodza-textarea__ring-track" cx="10" cy="10" r="8"/><circle class="kodza-textarea__ring" cx="10" cy="10" r="8" pathLength="1"/></svg><span class="kodza-textarea__left"></span></span>
  </p>
</div>

<div class="kodza-textarea">
  <label class="kodza-textarea__box">
    <textarea class="kodza-textarea__input" name="notes" rows="2" placeholder=" " disabled>Release notes are locked until Friday. Not on our watch.</textarea>
    <span class="kodza-textarea__label">Release notes</span>
  </label>
</div>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Textarea
   A textarea in the Text Field box: the label folds up as you type, the height eases to fit
   the text instead of jumping (no scrollbar, no handle), and a ring fills as you near the
   limit (data-max, or maxlength); the characters left show up in the last fifth, and the ring
   firms up at zero. The hint gives way to the error (data-error) without anything moving.
   Everything is tuned with the --kz-textarea-* variables. */
.kodza-textarea {
  --kz-textarea-bg: #ffffff;
  --kz-textarea-fg: #0a0a0a;
  --kz-textarea-muted: rgba(10, 10, 10, 0.6);
  --kz-textarea-line: rgba(10, 10, 10, 0.14);
  --kz-textarea-line-hover: rgba(10, 10, 10, 0.3);
  --kz-textarea-soft: rgba(10, 10, 10, 0.06);
  --kz-textarea-error: #0a0a0a;
  --kz-textarea-radius: 12px;
  --kz-textarea-pad: 16px;
  --kz-textarea-ease: cubic-bezier(0.22, 1, 0.36, 1);

  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 460px;
  color: var(--kz-textarea-fg);
}

.kodza-textarea__box {
  position: relative;
  display: block;
  padding: 28px var(--kz-textarea-pad) 12px;
  border-radius: var(--kz-textarea-radius);
  background: var(--kz-textarea-bg);
  box-shadow: inset 0 0 0 1px var(--kz-textarea-line);
  cursor: text;
  transition: box-shadow 0.25s ease;
}

.kodza-textarea__box:hover {
  box-shadow: inset 0 0 0 1px var(--kz-textarea-line-hover);
}

.kodza-textarea__box:focus-within {
  box-shadow: inset 0 0 0 1.5px var(--kz-textarea-fg), 0 0 0 4px var(--kz-textarea-soft);
}

.kodza-textarea__input {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 22px;
  outline: none;
  resize: none;
}

/* The label: in the box at rest, folded up once focused or filled */
.kodza-textarea__label {
  position: absolute;
  top: 18px;
  left: var(--kz-textarea-pad);
  color: var(--kz-textarea-muted);
  font-size: 15px;
  line-height: 1;
  pointer-events: none;
  transform-origin: left top;
  transition: transform 0.35s var(--kz-textarea-ease);
}

.kodza-textarea__box:focus-within .kodza-textarea__label,
.kodza-textarea__input:not(:placeholder-shown) ~ .kodza-textarea__label {
  transform: translateY(-8px) scale(0.8);
}

/* The foot: hint or error on the left, the counter on the right */
.kodza-textarea__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1.4;
}

.kodza-textarea__note {
  display: grid;
  min-width: 0;
  overflow: hidden;
}

.kodza-textarea__hint,
.kodza-textarea__error {
  grid-area: 1 / 1;
  transition: opacity 0.25s ease, transform 0.4s var(--kz-textarea-ease);
}

.kodza-textarea__hint {
  color: var(--kz-textarea-muted);
}

.kodza-textarea__error {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--kz-textarea-error);
  font-weight: 500;
  opacity: 0;
  transform: translateY(100%);
}

.kodza-textarea__error::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6.5' fill='none' stroke='black' stroke-width='1.5'/%3E%3Cpath d='M8 4.5v4.2M8 10.9v.1' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6.5' fill='none' stroke='black' stroke-width='1.5'/%3E%3Cpath d='M8 4.5v4.2M8 10.9v.1' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.kodza-textarea:has(.kodza-textarea__input[aria-invalid="true"]) .kodza-textarea__box {
  box-shadow: inset 0 0 0 1.5px var(--kz-textarea-error);
}

.kodza-textarea:has(.kodza-textarea__input[aria-invalid="true"]) .kodza-textarea__hint {
  opacity: 0;
  transform: translateY(-100%);
}

.kodza-textarea:has(.kodza-textarea__input[aria-invalid="true"]) .kodza-textarea__error {
  opacity: 1;
  transform: none;
}

/* The counter: a ring that fills, and the characters left near the end */
.kodza-textarea__count {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--kz-textarea-muted);
}

.kodza-textarea__count svg {
  width: 20px;
  height: 20px;
  transform: rotate(-90deg);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.kodza-textarea__count circle {
  fill: none;
  stroke-width: 2.4;
}

.kodza-textarea__ring-track {
  stroke: var(--kz-textarea-soft);
}

.kodza-textarea__ring {
  stroke: var(--kz-textarea-muted);
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--kz-used, 0));
  stroke-linecap: round;
  transition: stroke-dashoffset 0.2s ease, stroke 0.2s ease;
}

.kodza-textarea.is-near .kodza-textarea__ring {
  stroke: var(--kz-textarea-fg);
}

.kodza-textarea.is-full .kodza-textarea__count svg {
  transform: rotate(-90deg) scale(1.15);
}

.kodza-textarea__left {
  display: inline-grid;
  min-width: 2ch;
  overflow: hidden;
  text-align: right;
  opacity: 0;
  transform: translateX(4px);
  transition: opacity 0.2s ease, transform 0.3s var(--kz-textarea-ease);
}

.kodza-textarea__left > span {
  grid-area: 1 / 1;
}

.kodza-textarea.is-near .kodza-textarea__left {
  color: var(--kz-textarea-fg);
  opacity: 1;
  transform: none;
}

/* Disabled */
.kodza-textarea__box:has(.kodza-textarea__input:disabled) {
  background: var(--kz-textarea-soft);
  box-shadow: none;
  color: var(--kz-textarea-muted);
  cursor: not-allowed;
}

.kodza-textarea__input:disabled {
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-textarea__box,
  .kodza-textarea__label,
  .kodza-textarea__hint,
  .kodza-textarea__error,
  .kodza-textarea__count svg,
  .kodza-textarea__ring,
  .kodza-textarea__left {
    transition-duration: 0.01ms !important;
  }
}

/* Theming example — on a dark background:
.dark-section .kodza-textarea {
  --kz-textarea-bg: #161616;
  --kz-textarea-fg: #f2f2f0;
  --kz-textarea-muted: rgba(242, 242, 240, 0.62);
  --kz-textarea-line: rgba(255, 255, 255, 0.14);
  --kz-textarea-line-hover: rgba(255, 255, 255, 0.3);
  --kz-textarea-soft: rgba(255, 255, 255, 0.07);
  --kz-textarea-error: #f2f2f0;
}
*/

/* kodza-guard 9a05c8f203cf — generated by Kodza, do not edit.
   Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
   component. :not(#_) is always true and weighs as much as an id, so these lines win over
   theme rules made of classes and tags. Customise the component through its --kz-* variables. */

/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */

:where(.kodza-textarea__box):not(#_) {
  color: revert;
}

/* What the browser gives, on everything the component leaves to it */

.kodza-textarea:not(#_),
.kodza-textarea__label:not(#_),
.kodza-textarea__note:not(#_),
.kodza-textarea__hint:not(#_),
.kodza-textarea__error:not(#_),
.kodza-textarea__count:not(#_),
.kodza-textarea__ring-track:not(#_),
.kodza-textarea__ring:not(#_),
.kodza-textarea__left:not(#_),
.kodza-textarea__left span:where(:not([class*="kodza-"])):not(#_) {
  box-sizing: revert;
}

.kodza-textarea__box:not(#_) {
  border: revert;
  margin: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-textarea__input:not(#_) {
  border-radius: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
}

.kodza-textarea__foot:not(#_) {
  border: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-weight: revert;
  font-style: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-textarea__count svg:where(:not([class*="kodza-"])):not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-textarea__count svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-textarea__count svg:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
  display: none;
}

.kodza-textarea__error:not(#_)::before {
  box-sizing: revert;
}

/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */

.kodza-textarea:not(#_) {
  width: min(100%, 460px);
}

.kodza-textarea__box:not(#_) {
  position: relative;
  display: block;
  padding: 28px var(--kz-textarea-pad) 12px;
  border-radius: var(--kz-textarea-radius);
  background: var(--kz-textarea-bg);
  box-shadow: inset 0 0 0 1px var(--kz-textarea-line);
  transition: box-shadow 0.25s ease;
}

.kodza-textarea__box:hover:not(#_) {
  box-shadow: inset 0 0 0 1px var(--kz-textarea-line-hover);
}

.kodza-textarea__box:focus-within:not(#_) {
  box-shadow: inset 0 0 0 1.5px var(--kz-textarea-fg), 0 0 0 4px var(--kz-textarea-soft);
}

.kodza-textarea__input:not(#_) {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 22px;
  outline: none;
  resize: none;
}

.kodza-textarea__foot:not(#_) {
  display: flex;
  margin: 0;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1.4;
}

.kodza-textarea:has(.kodza-textarea__input[aria-invalid="true"]) .kodza-textarea__box:not(#_) {
  box-shadow: inset 0 0 0 1.5px var(--kz-textarea-error);
}

.kodza-textarea__count svg:not(#_) {
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.kodza-textarea__box:has(.kodza-textarea__input:disabled):not(#_) {
  background: var(--kz-textarea-soft);
  box-shadow: none;
  color: var(--kz-textarea-muted);
}

.kodza-textarea__input:disabled:not(#_) {
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  .kodza-textarea__box:not(#_),
  .kodza-textarea__count svg:not(#_) {
    transition-duration: 0.01ms !important;
  }
}
```

```js
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Textarea
// Grows the textarea to fit its text (the height eases instead of jumping), fills the counter
// ring, shows the characters left in the last fifth, and writes the error (data-error, or the
// browser's own) when the text is invalid: judged when the visitor leaves, then live.
(() => {
  const SELECTOR = '.kodza-textarea';
  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  let uid = 0;

  // One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
  function mount(root, signal) {
    const input = root.querySelector('.kodza-textarea__input');
    const hint = root.querySelector('.kodza-textarea__hint');
    const error = root.querySelector('.kodza-textarea__error');
    const left = root.querySelector('.kodza-textarea__left');
    if (!input) return;
    const max = Number(root.dataset.max) || (input.maxLength > 0 ? input.maxLength : 0);
    const id = `kodza-textarea-${++uid}`;
    const described = [];
    if (hint) described.push((hint.id = `${id}-hint`));
    if (error) described.push((error.id = `${id}-error`));
    if (described.length) input.setAttribute('aria-describedby', described.join(' '));

    // The height follows the text, easing from the old height to the new one
    let height = 0;
    let growing = null;
    const fit = (animate) => {
      const from = input.offsetHeight;
      input.style.height = 'auto';
      const to = Math.max(input.scrollHeight, 44);
      input.style.height = `${to}px`;
      if (animate && !reduceMotion && height && Math.abs(to - from) > 1) {
        growing?.cancel();
        growing = input.animate([{ height: `${from}px` }, { height: `${to}px` }], { duration: 220, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' });
      }
      height = to;
    };

    // The characters left roll to their new number
    if (left) left.replaceChildren(Object.assign(document.createElement('span'), { textContent: '' }));
    const roll = (text) => {
      const prev = left.lastElementChild;
      if (prev.textContent === String(text)) return;
      const span = Object.assign(document.createElement('span'), { textContent: text });
      left.append(span);
      if (reduceMotion || !root.classList.contains('is-near')) return prev.remove();
      const timing = { duration: 220, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' };
      prev.animate([{ transform: 'none' }, { transform: 'translateY(-110%)' }], { ...timing, fill: 'forwards' }).finished.then(() => prev.remove());
      span.animate([{ transform: 'translateY(110%)' }, { transform: 'none' }], timing);
    };

    const count = () => {
      if (!max) return;
      const used = Math.min(1, input.value.length / max);
      root.style.setProperty('--kz-used', used.toFixed(3));
      root.classList.toggle('is-near', used >= 0.8);
      root.classList.toggle('is-full', used >= 1);
      if (left) roll(max - input.value.length);
    };

    const check = () => {
      if (!error) return;
      const bad = !input.validity.valid;
      error.textContent = bad ? input.dataset.error || input.validationMessage : '';
      input.setAttribute('aria-invalid', String(bad));
    };

    input.addEventListener('input', () => {
      fit(true);
      count();
      if (input.getAttribute('aria-invalid') === 'true') check();
    }, { signal });
    input.addEventListener('blur', check, { signal });
    window.addEventListener('resize', () => fit(false), { signal });
    document.fonts?.ready.then(() => fit(false));

    fit(false);
    count();
  }

  // Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
  // event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
  // markup back. For themes and apps that swap content without a page load.
  const instances = new WeakMap();
  const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
  const init = (scope) => find(scope).forEach((root) => {
    if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
    const controller = new AbortController();
    instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
    mount(root, controller.signal);
    root.classList.add('is-ready');
  });
  const destroy = (scope) => find(scope).forEach((root) => {
    const instance = instances.get(root);
    if (!instance) return;
    instances.delete(root);
    instance.controller.abort();
    [...root.attributes].forEach((a) => root.removeAttribute(a.name));
    instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
    root.innerHTML = instance.html;
  });
  document.addEventListener('kodza:init', (event) => init(event.detail?.root));
  document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
  init();
  // Loaded in <head>, the script runs before the markup exists: once more when it is parsed
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
```

Free to use, from Kodza (https://kodza.dev).
