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

Tailwind CSS Remove Element Plugin API

Headless, unstyled remove element plugin built with JavaScript and TypeScript, including installation, usage, options, methods, events, and selectors.

JavaScript Typescript

Installation

To get started, install Remove Element 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/remove-element via npm

    Terminal
                              
                                npm i @preline/remove-element
                              
                            
  2. Add the plugin CSS

    Use @source to register the plugin's JavaScript path for Tailwind CSS scanning, then @import the plugin's CSS files into your Tailwind CSS file.

    main.css
                              
                                @import "tailwindcss";
                                
                                /* @preline/remove-element */
                                /* [!code highlight:3] */
                                @source "../node_modules/@preline/remove-element/*.js";
                                @import "./node_modules/@preline/remove-element/variants.css";
                                @import "./node_modules/@preline/remove-element/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/remove-element";
                              
                            
    JavaScript (non-auto)
                              
                                import HSRemoveElement from "@preline/remove-element/non-auto";
                                
                                HSRemoveElement.autoInit();
                                
                                // Or initialize a specific element manually
                                const el = document.querySelector("#remove-element");
                                if (el) new HSRemoveElement(el);
                              
                            

Example

Remove card with a dismissable button.

Basic usage

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

HTML
                      
                        <div id="dismiss-unstyled" class="inline-flex justify-between items-center w-full">
                          <h3>
                            Remove element card
                          </h3>
                          <button type="button" class="inline-flex justify-center items-center size-4" data-hs-remove-element="#dismiss-unstyled">
                            <span class="sr-only">Close</span>
                            <svg class="shrink-0 size-4" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
                          </button>
                        </div>
                      
                    

Data Options

Name Description Options Default value
data-hs-remove-element The element to be removed. This must be a valid selector. Should be added to the button (trigger). null
data-hs-remove-element-options Options that can be added via the data attribute. Should be added to the button (trigger).
:removeTargetAnimationClass Some valid CSS class. string hs-removing

Methods

The HSRemoveElement 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
HSRemoveElement.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 } = HSRemoveElement.getInstance('#remove-element', 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.

Remove Element

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

View Remove Element examples

Remove Element

© 2026 Preline Labs.