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

Tailwind CSS PIN Input Plugin API

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

JavaScript Typescript

Installation

To get started, install Pin Input 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/pin-input via npm

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

Example

Wrap the PIN Input's toggle data-hs-pin-input-item within data-hs-pin-input.

Basic usage

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

HTML
                      
                        <div data-hs-pin-input>
                          <input type="text" data-hs-pin-input-item>
                          <input type="text" data-hs-pin-input-item>
                          <input type="text" data-hs-pin-input-item>
                          <input type="text" data-hs-pin-input-item>
                        </div>
                      
                    

Data Options

Name Description Options Default value
data-hs-pin-input Activate a Pin Input by specifying on an element. Should be added to the container.
:availableCharsRE Regular expression string for available characters. RegExp ^[a-zA-Z0-9]+$
data-hs-pin-input-item Determines which element inside the initialized container will be responsible for entering data. Should be added to the input.

Class Options

Name Description Options Default value
autofocus If one of the fields has this class, it will be focused when the page loads.

Tailwind Modifiers

Name Description
hs-pin-input-active:* The class is added to the input when the PIN has set up.

Methods

The HSPinInput 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
HSPinInput.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 } = HSPinInput.getInstance('#pin-input', true);
                        const destroyBtn = document.querySelector('#destroy-btn');
                        
                        destroyBtn.addEventListener('click', () => {
                          element.destroy();
                        });
                      
                    

Events

Method Description Returned value
on:completed The event is triggered when the PIN has set up. Current value

When pin is filled example.

JavaScript
                      
                        const el = HSPinInput.getInstance('#pin-input');

                        el.on('completed', ({currentValue}) => {...});
                      
                    

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.

PIN Input

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

View PIN Input examples

PIN Input

© 2026 Preline Labs.