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
import {
PasswordInput, PasswordInputGroup, PasswordInputInput,
PasswordInputTrigger,
} from "@/components/ui/password-input";<PasswordInput className="w-full max-w-64">
<PasswordInputGroup>
<PasswordInputInput placeholder="Enter password" />
<PasswordInputTrigger />
</PasswordInputGroup>
</PasswordInput>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 labeled with what it will do, Show password or Hide password, and toggles on Enter and Space.
Clicking the eye leaves focus in the input, and Ark UI turns off spell check and auto-capitalization on it, so a shown password isn't spell-checked or capitalized. Give the field a visible label: inside a Field, Ark UI 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 as you type. 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. Ark UI ties the label to the input.
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 React Password Input?
Hold a boolean in state, pass it as visible on PasswordInput and update it in onVisibilityChange, whose details.visible is the state the eye button asks for. 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 React?
PasswordInputInput renders a plain input, so read it as you would any input: pass value and update it in onChange from the event's target, as the Controlled demo does.
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. Ark UI 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, ignorePasswordManagers adds the attributes that keep 1Password, LastPass, Bitwarden, Dashlane and Proton Pass away.
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 whose label, Show password or Hide password, says what pressing it will do.
Inside a Field, Ark UI 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 translations to PasswordInput with a visibilityTrigger function, which receives whether the password is visible and returns the button's label, such as Mostrar contraseña while it's hidden and Ocultar contraseña while it shows. Ark UI falls back to Show password and Hide password.
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"
autoComplete?"current-password" | "new-password"
The autocomplete attribute for the password input.
- Type
"current-password" | "new-password"- Default
"current-password"
defaultVisible?boolean
The default visibility of the password input.
dir?"ltr" | "rtl"
The document's text/writing direction.
- Type
"ltr" | "rtl"- Default
"ltr"
disabled?boolean
Whether the password input is disabled.
id?string
The unique identifier of the machine.
ids?object
The ids of the password input parts.
- Type
{ input?: string; visibilityTrigger?: string }
ignorePasswordManagers?boolean
When true, the input will ignore password managers.
**Only works for the following password managers**
- 1Password, LastPass, Bitwarden, Dashlane, Proton Pass
invalid?boolean
The invalid state of the password input.
name?string
The name of the password input.
onVisibilityChange?(details: VisibilityChangeDetails) → void
Function called when the visibility changes.
- Type
(details: VisibilityChangeDetails) → void- Parameters
details– { visible: boolean }- Returns
void
readOnly?boolean
Whether the password input is read only.
required?boolean
Whether the password input is required.
translations?object
The localized messages to use.
- Type
{ visibilityTrigger?: (visible: boolean) → string }
visible?boolean
Whether the password input is visible.
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-disabled?string
Present when disabled.
data-invalid?string
Present when invalid.
data-readonly?string
Present when read-only.
data-size?string
Mirrors size.
PasswordInputInput
<input> data-slot="password-input-input"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
data-disabled?string
Present when disabled.
data-invalid?string
Present when invalid.
data-readonly?string
Present when read-only.
data-state"visible" | "hidden"
"visible" or "hidden".
- Type
"visible" | "hidden"
PasswordInputGroup
<div> data-slot="password-input-control"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-disabled?string
Present when disabled.
data-invalid?string
Present when invalid.
data-readonly?string
Present when read-only.
PasswordInputIndicator
<span> data-slot="password-input-indicator"
fallback?React.ReactNode
The fallback content to display when the password is not visible.
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
data-disabled?string
Present when disabled.
data-invalid?string
Present when invalid.
data-readonly?string
Present when read-only.
data-state"visible" | "hidden"
"visible" or "hidden".
- Type
"visible" | "hidden"
PasswordInputTrigger
<button> data-slot="password-input-visibility-trigger"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
data-disabled?string
Present when disabled.
data-readonly?string
Present when read-only.
data-state"visible" | "hidden"
"visible" or "hidden".
- Type
"visible" | "hidden"
usePasswordInput
autoComplete?"current-password" | "new-password"
The autocomplete attribute for the password input.
- Type
"current-password" | "new-password"- Default
"current-password"
defaultVisible?boolean
The default visibility of the password input.
disabled?boolean
Whether the password input is disabled.
id?string
The unique identifier of the machine.
ids?object
The ids of the password input parts.
- Type
{ input?: string; visibilityTrigger?: string }
ignorePasswordManagers?boolean
When true, the input will ignore password managers.
**Only works for the following password managers**
- 1Password, LastPass, Bitwarden, Dashlane, Proton Pass
invalid?boolean
The invalid state of the password input.
name?string
The name of the password input.
onVisibilityChange?(details: VisibilityChangeDetails) → void
Function called when the visibility changes.
- Type
(details: VisibilityChangeDetails) → void- Parameters
details– { visible: boolean }- Returns
void
readOnly?boolean
Whether the password input is read only.
required?boolean
Whether the password input is required.
translations?object
The localized messages to use.
- Type
{ visibilityTrigger?: (visible: boolean) → string }
visible?boolean
Whether the password input is visible.











