advanced forms

Tailwind CSS Pin Input

The Pin Input component facilitates quick PIN entry for scenarios like multi-factor authentication, supporting features like regex validation and clipboard pasting.

Class Name
Type
Description
pin-inputComponentContainer style class.
pin-input-underlineComponentUnderline style.
pin-input-active:{tw-utility-class}ModifierAdds tailwind classes when the pin input is active (triggered when the PIN has set up).
pin-input-smResponsivePin input with small size.
pin-input-lgResponsivePin input with large size.

Basic pin input example.

Pin input with placeholder.

Default pin input example.

Apply the pin-input-underline class to change the pin input style to an underline.

Pin input has 3 size small default and large. Use pin-input-sm for small size and pin-input-lg for large size.

Underline pin input sizes example.

To disable pointer events and prevent focusing, add the disabled boolean attribute to an input.

Control the number of pin input as per you preference.

By default, this accepts both letters and numbers. To restrict input to numbers/letters only, set "availableCharsRE" to "^[a-z]+$" / "^[0-9]+$".

To restrict the pin input to accept only specific numbers, you can use a regular expression. For example, to ensure the pin input accepts only the numbers 1 to 5, set "availableCharsRE" to "^[1-5]+$".

Conceal the entered value by setting the type attribute to “password”.

To display a numeric keyboard on iOS (note: this does not apply for Android), Use autocomplete="one-time-code" and type="tel".

PARAMETERS
DESCRIPTION
OPTIONS
DEFAULT VALUE
data-pin-inputActivate a Pin Input by specifying on an element.--
:availableCharsREString of regular expression for allowed characters.RegExp^[a-zA-Z0-9]+$
autofocusIf one of the fields has this class, it will be focused when the page loads.--

The HSPinInput object is contained within the global window object.

METHOD
DESCRIPTION
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.
METHOD
DESCRIPTION
RETURNING VALUE
on:completedThe event is triggered when the PIN has set up.Current value

Assign an ID to data-pin-input, and you can then trigger an event using that ID.

Below is a demonstration of how to use the event. We’ve included JavaScript to handle the events, allowing it to execute when the corresponding event is fired. To test these events, monitor your console.

When pin input is completed example.

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

el.on('completed', ({instance}) => {console.log("Hello")});