shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A password input is a text field that hides what's typed behind dots, with an eye button at the end that shows the characters and hides them again. Use it wherever someone types a secret: a sign-in form, a sign-up form, a password reset, a field for an API key.
For text that isn't secret, a plain Input is enough. A one-time code sent by text message reads better in an Input OTP, with one box per digit.
Installation
Anatomy

Usage
<script setup lang="ts">
import {
PasswordInput, PasswordInputGroup, PasswordInputInput,
PasswordInputTrigger,
} from "@/components/ui/password-input";
</script>
<template>
<PasswordInput class="w-full max-w-64">
<PasswordInputGroup>
<PasswordInputInput placeholder="Enter password" />
<PasswordInputTrigger />
</PasswordInputGroup>
</PasswordInput>
</template>
Accessibility
The field is a real input of type password while the characters are hidden and text while they show, so screen readers and password managers treat it as a password field. The eye button is a Tab stop that keeps the name Show password and says whether the password shows through aria-pressed. It toggles on Enter and Space.
Clicking the eye leaves focus in the input, and the input turns off spell check, autocorrect and auto-capitalization, so a shown password isn't spell-checked or changed by a phone keyboard. Submitting or resetting the form hides a shown password again. Give the field a visible label: inside a Field, UI SDK ties the FieldLabel to the input.
- Tab
- Moves focus from the input to the eye button, then on to the next field.
- Shift+Tab
- Moves focus from the eye button back to the input.
- Enter
- When focus is on the eye button, shows or hides the password.
- Space
- When focus is on the eye button, shows or hides the password.
Demos
Auto hide
Pressing the eye shows the password and starts a three-second timer, after which it's masked again whether or not anyone presses the button. The demo controls visible so the timer can set it back, and clears the timer when the password is hidden sooner, so each reveal gets its full three seconds. Use it where a revealed password shouldn't linger, such as a shared screen or a kiosk sign-in.
Autocomplete
Two fields: Current password, with autoComplete set to current-password, and New password, with new-password. The first lets a password manager fill a saved password at sign-in. The second tells the browser to offer a generated one on sign-up or a reset, and a change-password form needs both.
Controlled
The password lives in your own state, and the line under the field counts its characters each time the field loses focus, since this demo listens to its change event. Hold the value when something reacts to it while typing, such as a strength meter or a confirm field that has to match. When you only need it on submit, read it from the form data instead.
Controlled visibility
The page keeps visible in its own state and updates it whenever the eye button asks to change it, so the button is no longer the only thing that can mask or reveal the password. Use it when something else must change it too, such as a form reset that hides it again. The Auto hide demo adds a timer to this setup.
Custom indicator
A PasswordInputIndicator inside the trigger swaps the eye for a lock while the password is hidden, set as its fallback, and an open lock while it shows. Both icons carry aria-hidden, because the button's label already says what it does. Use your own pair when the product already has an icon for hidden content.
Disabled
disabled on PasswordInput keeps the saved password, correct-horse, in the field but stops both typing and the eye button, and the line underneath says the field is disabled. Use it when the password can't be changed from this screen, such as an account that signs in through single sign-on. Say why in that line, since a faded field doesn't explain itself.
Field
The input sits in a Field labeled Password, with the rule, at least 8 characters, written underneath where people read it before they submit. UI SDK ties the label to the input through the Field.
Invalid
invalid on the Field and on PasswordInput turns the border red and sets aria-invalid on the input, and the line underneath asks for a valid password. Show it after a failed sign-in, or once the value is long enough to judge. Put the reason in that line, such as the rule that failed, since a red border says only that something is wrong.
Size lg
size set to lg makes the field 36 pixels tall, with the eye button inside it. Use it when the password is the main control on a page of its own, such as a reset screen, next to other large inputs and buttons.
Size md
md is the default size, written out here to compare with the other two. The field takes the height of a default Input Group in your style, so it lines up with the other inputs in a form. Leave size out and you get the same.
Size sm
size set to sm brings the field down to 28 pixels, eye button included, for a dialog, a sidebar or a row of small controls. Use it only when the fields around it are small too, or the password field looks out of place beside them.
FAQ
How do I show or hide the password from code in a Vue Password Input?
Bind v-model:visible on PasswordInput to a boolean ref, which the eye button then updates. To only start with the password shown, set defaultVisible instead and leave the rest to the button.
The Controlled visibility demo holds it in state, and Auto hide adds a timer.
How do I get the value of a Password Input in Vue?
Bind v-model:value on PasswordInput to a string ref, which updates on every keystroke, or listen to its @value-change, which receives the new password first. PasswordInputInput also takes value with an @input or @change listener, as a plain input does. The Controlled demo listens to @change, which fires only when the field loses focus.
In a form, give PasswordInputInput a name and read the password from the submitted form data instead, which keeps it out of your component state.
How do I make password managers fill or generate a password in the Password Input?
Set autoComplete on PasswordInput. UI SDK uses current-password when you leave it out, which lets a password manager fill a saved password at sign-in, and new-password on a sign-up or reset form lets the browser offer a generated one. For a secret that isn't a login, such as an API key, set it to off and add the managers' own opt-out attributes to PasswordInputInput, such as data-1p-ignore for 1Password.
The Autocomplete demo has one of each.
Can a Password Input hide the password again after a few seconds?
Yes, by controlling visible: when it turns on, start a timer that sets it back to hidden. The Auto hide demo does this with three seconds, so a revealed password doesn't sit on a shared screen.
Clear the timer when the person hides the password themselves or the component unmounts, as the demo does. Otherwise a timer from an earlier reveal can mask a later one before its three seconds are up.
How do I change the eye icons of the Password Input?
Put a PasswordInputIndicator inside PasswordInputTrigger with your two icons. The one in fallback shows while the password is hidden, and the one inside the indicator shows while it's visible, as in the Custom indicator demo with a closed and an open lock.
Mark both icons aria-hidden, since the button's label already says what it does. To change the default eye pair everywhere, edit PasswordInputIndicator in components/ui/password-input, which is your file once installed.
How do I use the Password Input in a form with validation?
Give PasswordInputInput a name, and the password submits with the form like any input. Native attributes such as required go on it too and behave as they do on any input.
Put the field in a Field with its rule as the description, as the Field demo does. When your check fails, set invalid on PasswordInput, which turns the border red and sets aria-invalid on the input, and say what failed under it, as in the Invalid demo.
Is the Password Input accessible to screen reader users?
Yes, once it has a visible label. The input stays a real password input while hidden, and the eye button is a Tab stop named Show password, whose pressed state says whether the password shows.
Inside a Field, UI SDK ties the FieldLabel to the input. Clicking the eye leaves focus in the input, so typing carries on.
How do I translate the Show password label of the Password Input?
Pass aria-label to PasswordInputTrigger, such as Mostrar contraseña, which replaces Show password. The name doesn't change while the password shows, because the button's pressed state says which way it is, so one string is enough. To translate it everywhere, edit that string in PasswordInputTrigger, in components/ui/password-input, which is your file once installed.
Keep the label describing the action, since it's what a screen reader says on the button.
API Reference
PasswordInput
<div> data-slot="password-input"
value?string
The value, for a controlled field. Two-way with v-model.
- Default
(valueLifted ? liftedValue : undefined)
defaultValue?string
The value it starts with. A form reset returns here.
autoComplete?"current-password" | "new-password" | "off" | (string & {})
What the browser and password managers fill in: "current-password" for signing in, "new-password" for signing up or changing it.
- Type
"current-password" | "new-password" | "off" | (string & {})- Default
"current-password"
controller?PasswordInputController
Reads, writes, shows and hides it from anywhere. Create one with createPasswordInputController().
debug?boolean
Logs every state change with its reason to the console, in development builds.
defaultVisible?boolean
The default visibility of the password input.
- Default
false
disabled?boolean
Disables the field and the toggle. Inside a Field or a disabled <fieldset>, they follow it.
- Default
false
form?string
The id of the form the field belongs to, when it isn't inside it.
invalid?boolean
Whether it's invalid.
- Default
false
name?string
The name the password submits under. Inside a Field, the Field's name.
readOnly?boolean
Makes the field read-only. The toggle still shows and hides it.
required?boolean
Whether a password is required to submit the form.
size?"sm" | "md" | "lg"
The size.
- Type
"sm" | "md" | "lg"- Default
"md"
visible?boolean
Whether the password input is visible.
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
@value-change(value: string, details: ChangeDetails<InputValueChangeReason>) → void
Called when the user changes the value: typing ("input-change"), a Clear part ("clear-press"), a form reset ("reset") or a controller ("imperative"). details.cancel() keeps the value as it was.
- Type
(value: string, details: ChangeDetails<InputValueChangeReason>) → void- Parameters
value– stringdetails– ChangeDetails<InputValueChangeReason>- Returns
void
@visibility-change(details: { visible: boolean }) → void
Runs when the password is shown or hidden: by the toggle, or hidden again as its form submits or resets.
- Type
(details: { visible: boolean }) → void- Parameters
details– { visible: boolean }- Returns
void
data-capslock?string
Present while Caps Lock is on and the field has focus.
data-disabled?string
Present when disabled, by its own prop, a Field or a <fieldset>.
data-filled?string
Present while the field holds any text.
data-readonly?string
Present when the field is read-only.
data-required?string
Present when a password is required.
data-visible?string
Present while the password is shown, so the field is a text field.
PasswordInputGroup
debug?boolean
Logs every state change with its reason to the console, in development builds.
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
PasswordInputInput
<input> data-slot="input-group-control"
class?string
Merged with the part's classes.
data-capslock?string
Present while Caps Lock is on and the field has focus.
data-disabled?string
Present when disabled, by its own prop, a Field or a <fieldset>.
data-filled?string
Present while the field holds any text.
data-readonly?string
Present when the field is read-only.
data-required?string
Present when a password is required.
data-visible?string
Present while the password is shown, so the field is a text field.
PasswordInputTrigger
<button> data-slot="password-input-toggle"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-capslock?string
Present while Caps Lock is on and the field has focus.
data-disabled?string
Present when disabled, by its own prop, a Field or a <fieldset>.
data-filled?string
Present while the field holds any text.
data-readonly?string
Present when the field is read-only.
data-required?string
Present when a password is required.
data-size"icon-xs"
- Default
"icon-xs"
data-variant"ghost"
- Default
"ghost"
data-visible?string
Present while the password is shown, so the field is a text field.
PasswordInputIndicator
<span> data-slot="password-input-indicator"
fallback?VNode
The fallback content to display when the password is not visible.
class?string
Merged with the part's classes.











