Web Component

Input PIN

Allows users to input a sequence of one-character alphanumeric inputs.

Table of contents

Usage

The Input PIN component is a web component built from scratch to allow users to input a sequence of one-character alphanumeric inputs. This is particularly useful in scenarios such as:

  • Entering a verification code sent via SMS or email
  • Authenticating with a two-factor authentication system
  • Creating a secure password or passphrase

To get started, simply use the <uk-input-pin> markup in your HTML code.

Capturing values

There are several ways to capture values from the <uk-input-pin> component. The simplest approach is to add a name attribute to the component. When you do this, a hidden input field with the specified name will be automatically generated, allowing you to easily capture the selected value on your server.

Customize length

By default, the Input PIN component is set to accept 6 characters. However, you can easily customize this by adding the length attribute to the <uk-input-pin> element. Simply specify the desired length as a numerical value, and the component will automatically adjust to accommodate the specified number of inputs.

Separated input

By default, the input fields in the Input PIN component are displayed adjacent to each other. To add visual separation between each input, simply add the .uk-input-pin-separated class to the cls attribute. This will add gaps between each input, making it easier for users to distinguish between individual characters.

Size modifiers

There are several size modifiers available. Just add one of the following classes to the cls attribute to make the input smaller or larger.

ClassDescription
.uk-form-xsmallApplies extra small size.
.uk-form-smallApplies small size.
.uk-form-mediumApplies medium size.
.uk-form-largeApplies large size.

Disable input

To prevent user input, add the disabled attribute to the <uk-input-pin> element. This will disable all input fields, making it impossible for users to enter or modify the PIN sequence.

Error state

To indicate an error state in the form, simply add the .uk-form-danger class to the cls attribute. This will apply a “danger” state to the component, providing visual feedback to the user.

  • This field is required.

PR

Internationalization

The Input PIN component supports internationalization through multiple methods with the following priority order (highest to lowest):

  • Component-level i18n (via i18n attribute or script tag)
  • Global component-specific namespace (via <script id="uk-i18n">)
  • Default values

Using the i18n attribute

Using a configuration script

PR

Using global i18n

Place this in your document <head> or before any input-pin components:

Available i18n options

KeyDefaultDescription
labelPIN CodeMain label for the PIN input group
descriptionEnter {length}-digit codeDescription text (supports {length} placeholder)
field-labelDigit {n} of {total}ARIA label for individual fields (supports {n}, {total} placeholders)
loadedPIN input readyScreen reader announcement when component loads
completePIN entry completeScreen reader announcement when all fields are filled
field-filledField {n} filledScreen reader announcement when a field is filled (supports {n} placeholder)
invalid-characterInvalid character enteredScreen reader announcement for invalid input

Custom classes

The Input PIN component supports custom CSS classes through the cls attribute. This allows you to style specific elements within the PIN input without modifying the component’s internal structure.

Using simple string format

Apply a class to the default element (host-inner):

Using JSON object format

Target specific elements within the input pin:

Using configuration script

Available cls targets

TargetDescription
host-innerThe main container div
wrapperThe div wrapping all input fields
inputIndividual input fields
labelThe label element (visually hidden by default)
descriptionThe description element (visually hidden by default)

Custom inline styles

The Input PIN component supports custom inline styles through the stl attribute. This allows you to apply specific CSS styles to individual elements within the PIN input.

Using simple string format

Apply styles to the default element (host-inner):

Using JSON object format

Target specific elements with custom styles:

Using configuration script

Available stl targets

The stl attribute supports the same targets as the cls attribute. See the Available cls targets table above for a complete list of targetable elements.

Keyboard navigation

The Input PIN component provides comprehensive keyboard support:

KeyAction
Type characterAuto-advances to next field
BackspaceDeletes character and moves to previous field (if empty)
DeleteMoves to next field (if current is empty)
Arrow LeftMove to previous field
Arrow RightMove to next field
HomeJump to first field
EndJump to last filled field
Paste (Ctrl+V)Distributes pasted content across fields

Paste support

The component supports pasting complete PIN codes. When a user pastes text:

  • Content is automatically distributed across input fields
  • Text is trimmed to the PIN length
  • Pattern validation is applied (if configured)
  • Focus moves to the next empty field or blurs if complete
  • Invalid pastes are rejected with screen reader announcement

Preventing layout shift

When loading Web Components, there may be a brief delay before the content is fully rendered. This can result in a flash of unstyled content or unprocessed templates. To mitigate this issue, consider setting a predefined height on the parent element to prevent layout shift and ensure a smooth user experience.

Attributes

The following attributes are available for this component:

NameTypeDefaultDescription
autofocusBooleanfalseAutomatically focuses on the first input field when the component is rendered
lengthNumber6Number of PIN digits/characters to collect
input-modeStringnumericInput mode for mobile keyboards: numeric or text
patternStringPattern for input validation (e.g., [0-9] for digits only)
show-labelsBooleanfalseWhether to show labels and descriptions visually (default: hidden but accessible)
nameStringName attribute for the hidden input field, enabling form submission
disabledBooleanfalseDisables all input fields, making the entire component read-only
requiredBooleanfalseMarks the PIN input as required for form validation
valueStringPre-populated PIN value (validated against pattern if provided)
clsStringCustom CSS classes. Can be simple string or JSON object for targeting elements
stlStringCustom inline styles. Can be simple string or JSON object for targeting elements
i18nStringInternationalization strings as JSON object or via configuration script
force-prevent-rerenderBooleanfalsePrevents component rerendering (useful for HTMX or SPA scenarios)

Events

The Input PIN component triggers the following events:

NameDescription
uk-input-pin:changeFired when the PIN value changes. Event detail contains {value: string}.
uk-input-pin:completeFired when all PIN fields are filled. Event detail contains {value: string}.