--- 
title: Code Input
description: Multi-digit code entry (e.g., OTP)
category: components
a1Full: true
alias: otp, pin input
a1Densities: true
group: Forms & Inputs

module: NxCodeInputModule
components:
  - name: NxCodeInputComponent
    selector: nx-code-input
    inputs:
      - name: inputMode
        desc: "The inputmode of the input elements, controlling e.g. which mobile keyboard is shown. Unset by default, so the browser derives it from the native `type` attribute instead."
        default: input<NxCodeInputMode>()
        type: "InputSignal<'text' | 'numeric' | 'decimal' | 'tel' | undefined>"
      - name: digitsOnly
        desc: "Whether non-digit characters should be stripped from the entered value."
        default: input(false, { transform: booleanAttribute })
        type: "InputSignalWithTransform<boolean, unknown>"
      - name: inverse
        desc: "Whether the code input should use negative styling."
        default: input<boolean, BooleanInput>(false, { transform: booleanAttribute })
        type: "InputSignalWithTransform<boolean, BooleanInput>"
      - name: length
        desc: "The length of the code input. Default: 6."
        type: "number"
      - name: type
        desc: "The type of HTML input."
        type: "string"
      - name: tabindex
        desc: "Sets the tabindex of the contained input elements."
        type: "number"
      - name: convertTo
        desc: "Whether the form should auto capitalize or lowercase (optional)."
        type: "'lower' | 'upper'"
      - name: negative
        desc: "Whether the code input should use negative styling. This will be deprecated in favor of `inverse`."
        type: "BooleanInput"
      - name: disabled
        desc: "Whether the code input is disabled."
        type: "BooleanInput"
    methods:
      - name: setInputLength
        params: 
        desc: "Sets the length of the input fields."
        returnType: void
      - name: setDisabledState
        params:
          - name: isDisabled
            type: boolean
        desc: "Disables the code input. Part of the ControlValueAccessor interface required to integrate with Angular's core forms API."
        returnType: void
      - name: updateErrorState
        params: 
        returnType: void
      - name: getAriaLabel
        params:
          - name: keyIndex
            type: number
        returnType: string
      - name: selectInput
        params:
          - name: input
            type: HTMLInputElement
        desc: "Workaround preventing the selection error because the `setSelectionRange` is not supported on input['type=number']"
        returnType: void

---
# Overview
Use this component when you want users to input a one-time, fixed, and specific set of characters to be validated. There is no limit to how many fields can be used.

The code input component is primarily used for key codes that are generally meaningless and abide by specific character patterns.

This component can be used for anything ranging from one time codes sent via SMS or email verification codes on desktop or mobile.
