Interactive
Textarea autosize
Grows the textarea with its content. Browsers with CSS field-sizing do it natively; the script measures the others. max-height still caps it. Needs monsoon.js.
Needs monsoon.js. The styles work on their own, and the behavior comes from the optional interactive layer: add <script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script> or import 'monsooncss/js'. See the interactive layer.
Example
<textarea class="textarea max-w-md max-h-64" rows="2" data-m-autosize aria-label="Message">Write as much as you like: this box grows line by line, then scrolls once it reaches its maximum height.</textarea>JavaScript API
Attribute
data-m-autosize
Options
| Option | Description |
|---|---|
rows sets the starting height, max-height the limit |
Methods
| Method | Description |
|---|
Events
| Event | Description |
|---|
Classes
1 classes. Click a name to copy it. Utilities on the same element always win over component defaults, so any of them can be adjusted with plain utility classes.
| Class | Type | What it does |
|---|---|---|
| Base | Base class of the textarea autosize. On a <textarea> in the example. Sets block display, width, height, padding, text size and text style, and 9 custom properties.CSS |
Usage
The styles ship inside the same stylesheet as the utilities, and the behavior comes from the optional monsoon.js script, which enhances any element with a matching data-m attribute, including markup added later.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script>
<!-- Textarea autosize: start from the base class, then add modifiers -->
<textarea class="textarea max-w-md max-h-64" rows="2" data-m-autosize aria-label="Message">Write as much as you like: this box grows line by line, then scrolls once it reaches its maximum height.</textarea>Theme it with --seed on any ancestor, for example style="--seed: #0d9488", and force a scheme with class="dark" or class="light" on a wrapper.
Accessibility
- Give every control a visible
labellinked withfor, or anaria-labelwhen the purpose is obvious from context. Link help and error text witharia-describedby; invalid styles use:user-invalid, so they appear only after the user interacts. - Every interactive part shows a visible focus ring with
:focus-visible, and tone colors pair with-foregroundtokens that keep text at 4.5:1 or better in light and dark mode.