How to Handle the Hidden Autocomplete Field for Password Inputs in vue3-otp-input

The vue3-otp-input component automatically injects an invisible text input with autocomplete="off" before the visible OTP fields when input-type="password" is set, tricking browsers into autofilling the hidden field instead of the password inputs.

When building secure OTP or PIN entry flows with the vue3-otp-input library, enabling password mode via input-type="password" triggers browser password managers to attempt autofill, disrupting the user experience. The component solves this by rendering a hidden autocomplete field that intercepts these browser behaviors while keeping your OTP inputs clean.

Why Browsers Autofill Password OTP Fields

Modern browsers aggressively detect type="password" inputs and prompt users to save or autofill credentials. When vue3-otp-input renders six individual password boxes for a six-digit OTP, the browser treats each as a credential field, causing unwanted password manager popups and automatic filling of saved passwords into your PIN entry interface.

How vue3-otp-input Blocks Autocomplete

The component implements a defensive rendering strategy that places a decoy input field before the actual OTP inputs.

The Hidden Input Technique

When inputType equals "password", vue3-otp-input renders an invisible text input with specific attributes designed to capture browser autofill attempts:

<input
  autocomplete="off"
  name="hidden"
  type="text"
  style="display: none"
/>

This element appears in the DOM immediately before the visible OTP input fields. Because it carries name="hidden" and autocomplete="off", browsers identify it as the primary password field while ignoring the visible OTP boxes for autofill purposes.

Conditional Rendering Logic

The hidden field only appears when necessary. In src/components/vue3-otp-input.vue at lines 221-227, a v-if directive guards the hidden input:

<input
  v-if="inputType === 'password'"
  autocomplete="off"
  name="hidden"
  type="text"
  style="display: none"
/>

This ensures that standard OTP inputs (using input-type="tel" or "number") remain unaffected by the hidden field logic, maintaining clean DOM structure for non-password use cases.

Implementation Details in the Source Code

The autocomplete prevention mechanism lives in the main component file at src/components/vue3-otp-input.vue. The specific implementation spans lines 221-227, where the template conditionally renders the decoy input.

The architecture follows this pattern:

Concern Implementation
Password autofill prevention Hidden <input> with autocomplete="off" placed before visible OTP fields
Conditional activation v-if="inputType === 'password'" ensures logic only applies to password mode
Visual cleanliness style="display: none" removes the element from the layout flow
Browser compatibility Using type="text" instead of type="password" avoids browsers ignoring autocomplete="off" on actual password fields
Seamless API Developers only need to set the input-type prop; the component handles the hidden field automatically

Practical Usage Examples

To activate the hidden autocomplete field in your Vue application, simply set the input-type prop to "password":

<template>
  <v-otp-input
    v-model:value="otpCode"
    :num-inputs="6"
    input-type="password"
    :should-auto-focus="true"
    @on-complete="handleComplete"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import VOtpInput from 'vue3-otp-input';

const otpCode = ref('');
const handleComplete = (value: string) => {
  console.log('Secure OTP entered:', value);
};
</script>

When input-type="password" is active, inspecting the DOM reveals the hidden field immediately preceding the visible OTP inputs:

<!-- Hidden autocomplete interceptor -->
<input autocomplete="off" name="hidden" type="text" style="display: none">
<!-- Visible OTP inputs follow -->
<input type="password" ...>
<input type="password" ...>

To toggle between visible and hidden OTP entry modes dynamically, bind the input-type prop to a reactive variable:

<v-otp-input
  v-model:value="securityCode"
  :num-inputs="4"
  :input-type="isSecureMode ? 'password' : 'tel'"
/>

Summary

  • vue3-otp-input automatically prevents browser autofill on password-type OTP fields by rendering a hidden decoy input.
  • The hidden field uses autocomplete="off", name="hidden", and style="display: none" to intercept browser password managers.
  • Located in src/components/vue3-otp-input.vue at lines 221-227, the logic activates only when input-type="password".
  • Developers activate this protection by setting the input-type prop to "password" without additional configuration.

Frequently Asked Questions

Why does vue3-otp-input use a hidden text input instead of just adding autocomplete="off" to the password fields?

Browsers increasingly ignore autocomplete="off" on actual type="password" inputs to ensure password managers remain accessible for user convenience. By injecting a hidden type="text" field with autocomplete="off" before the visible password inputs, the component tricks the browser into targeting the decoy field for autofill, effectively protecting the OTP entry fields from unwanted password manager interference.

How do I verify that the hidden autocomplete field is actually rendering in my application?

Inspect the DOM using your browser's developer tools immediately before the visible OTP input elements. When input-type="password" is active, you should see an <input> element with attributes name="hidden", autocomplete="off", type="text", and style="display: none" positioned directly before the first visible OTP field. If you switch to input-type="tel" or "number", this hidden element should disappear from the DOM.

Does the hidden input field affect form submission or accessibility?

The hidden input does not impact form submission because it lacks a value attribute and carries name="hidden", which typically falls outside standard form data collection patterns. For accessibility, since the element uses style="display: none", it is removed from the accessibility tree and will not be announced by screen readers or navigable via keyboard, ensuring it remains a purely technical artifact for browser autofill prevention without degrading user experience.

Can I customize the hidden autocomplete field attributes or disable this behavior entirely?

The hidden field implementation is hardcoded in src/components/vue3-otp-input.vue at lines 221-227 and activates automatically whenever input-type="password" is specified. There is currently no exposed prop to modify the hidden field's attributes or disable this protection mechanism. If you require different autofill behavior, you would need to fork the repository and modify the template logic directly, or use input-type="tel" or "number" instead, which bypasses the hidden field rendering entirely.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →