Update v4.2 - New components, 10+ framework guides, and quality improvements. Visit Changelog

Tailwind CSS Textarea Auto Height Plugin API

Headless, unstyled textarea auto height plugin built with JavaScript and TypeScript, including installation, usage, options, methods, events, and selectors.

JavaScript Typescript

Installation

To get started, install Textarea Auto Height plugin via npm, else you can skip this step if you are already using Preline UI as a package.

  1. Install the plugin

    Install @preline/textarea-auto-height via npm

    Terminal
                              
                                npm i @preline/textarea-auto-height
                              
                            
  2. Add the plugin CSS

    @import the plugin's CSS file into your Tailwind CSS file.

    main.css
                              
                                @import "tailwindcss";
                                
                                /* @preline/textarea-auto-height */
                                /* [!code highlight:1] */
                                @import "./node_modules/@preline/textarea-auto-height/theme.css";
                              
                            
  3. Add the plugin JavaScript

    Include the JavaScript <script> that powers the interactive elements near the end of your </body> tag:

    HTML
                              
                            

    Additional Initialization Options

    Use the non-auto entry if you need manual initialization. In this mode, automatic initialization on page load is not included, so the component should be initialized explicitly.

    HTML (non-auto)
                              
                            

    Via bundler

    When using a bundler (Vite, webpack, etc.), import the plugin directly as an ES module.

    JavaScript (auto)
                              
                                import "@preline/textarea-auto-height";
                              
                            
    JavaScript (non-auto)
                              
                                import HSTextareaAutoHeight from "@preline/textarea-auto-height/non-auto";
                                
                                HSTextareaAutoHeight.autoInit();
                                
                                // Or initialize a specific element manually
                                const el = document.querySelector("#textarea");
                                if (el) new HSTextareaAutoHeight(el);
                              
                            

Example

A dynamic textarea that automatically adjusts its height based on content.

Basic usage

Prefer to create your own style? Here is a completely unstylized example.

HTML
                      
                        <textarea data-hs-textarea-auto-height></textarea>
                      
                    

Data Options

Name Description Options Default value
data-hs-textarea-auto-height If this attribute is added to the textarea, then automatic height calculation according to the content is enabled. Should be added to the textarea itself.
:defaultHeight Sets the default height (when no text is entered). number 0

Methods

The HSTextareaAutoHeight object is contained within the global window object

Method Description
Public methods
destroy() Destroys the instance, removes generated markup (if any), removes added classes and attributes.
Static methods
HSTextareaAutoHeight.getInstance(target, isInstance) Returns the element associated to the target.
  • target should be a Node or string (valid selector)
  • isInstance boolean. Returns the instance instead of Node if true

Destroy instance.

JavaScript
                      
                        const { element } = HSTextareaAutoHeight.getInstance('#textarea-autoheight', true);
                        const destroyBtn = document.querySelector('#destroy-btn');
                        
                        destroyBtn.addEventListener('click', () => {
                          element.destroy();
                        });
                      
                    

Ready to use Components

Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.

Textarea Autoheight

Explore ready-to-use Tailwind CSS examples built with Preline UI.

View Textarea Autoheight examples

Textarea Autoheight

© 2026 Preline Labs.