Tailwind CSS PIN Input Plugin API
Headless, unstyled PIN input plugin built with JavaScript and TypeScript, including installation, usage, options, methods, events, and selectors.
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.
-
Install the plugin
Install
@preline/pin-inputvia npmTerminalnpm i @preline/pin-input -
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"; -
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-autoentry 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);
Basic usage
Prefer to create your own style? Here is a completely unstylized example.
<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>
Methods
The HSPinInput object is contained within the global window object
Destroy instance.
const { element } = HSPinInput.getInstance('#pin-input', true);
const destroyBtn = document.querySelector('#destroy-btn');
destroyBtn.addEventListener('click', () => {
element.destroy();
});
Events
When pin is filled example.
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