--- title: Autosize summary: The autosize element will automatically adjust the textarea height and make it easier for users to follow as they type. docs-libs: [autosize] description: Make textareas grow automatically as users type with the autosize plugin, so longer text stays visible without manual resizing. related: [/ui/forms/elements] --- import Example from '@components/Example.astro'; import CodeDocs from '@components/CodeDocs.astro'; import TabsPackage from '@components/TabsPackage.astro'; import { Code } from 'astro:components'; import { site } from '@shared/lib/site.ts'; ## Overview A textarea keeps its height no matter how much text it holds, so long answers end up in a small scrolling box. The [autosize](https://github.com/jackmoore/autosize) plugin grows the field as the user types and shrinks it again when text is removed. ## Installation Install autosize with npm: Or include it from a CDN: `} /> The plugin only changes the height of the field, so it needs no CSS of its own. ## Usage Add `data-bs-toggle="autosize"` to a textarea. Tabler picks it up on page load, so there is nothing else to call. Set `rows` to choose the starting height. With `rows="1"` the field starts as a single line and grows from there. ## JavaScript Tabler initializes every element with `data-bs-toggle="autosize"` on page load. This is the code that runs: Call the plugin yourself when you add a textarea later, for example inside a modal or a row added by JavaScript: ```js autosize(document.getElementById('message')); ``` Autosize measures the field, so a hidden textarea gets the wrong height. Run `autosize.update()` once it becomes visible: ```js autosize.update(document.getElementById('message')); ``` ## Accessibility - Keep the `label` for the field. A growing textarea is still a normal form control and needs its name. - Let the field grow instead of setting a fixed `max-height`. Cutting the growth off brings back the scrolling box the plugin is meant to remove. - Do not remove the resize handle unless the field really grows on its own - without either one, a user cannot see long text.