Skip to main content

Password Input

An input for passwords and other sensitive values, with a built-in button that shows or hides the value. Pair it with Field to connect its label, description, and errors in a form.

When to use

  • Password fields on login, signup, and reset flows.
  • One-time tokens, recovery codes, or secrets the user must type accurately and may want to check visually before submitting.
  • Prefer Input when the value is never sensitive, or when the toggle would confuse the user, such as with masked formatting for phone numbers.
  • Prefer OtpInput when the value is a one-time passcode with one box for each character.

Validation

Set validation to show the validation status of the input.

Without a Field

Render the control on its own, and give it an accessible name with aria-label.

Visibility state

PasswordInput renders a native <input type="password"> with a trailing button. The button toggles the display between hidden (••••) and revealed (text).

The toggle is uncontrolled by default. Pass showValue to control the visibility from the outside, for example when one control reveals several password fields. Pass onValueVisibilityChange to receive the next visibility when the user clicks the built-in toggle. The eye icon animates on every visibility change, from the built-in toggle or from showValue, unless the user prefers reduced motion.

Accessibility

Always pair with a Label. The toggle is a focusable button with aria-pressed, named "Show value". The name does not change with state and does not contain the word "password", so a label query for the input matches one element. Its aria-controls points at the input's id: the id you pass, else a generated one. When disabled is set, the toggle is disabled too, so Tab skips the component. The input keeps autocomplete="current-password" / "new-password" semantics. Set autoComplete explicitly per flow.

Inside a Field.Item, pass id on Field.Item to set the input's id yourself, for example for a Playwright locator: Field.Label, the input, and the toggle's aria-controls all follow it.

Browser password managers

When revealed, the input switches to type="text". Some password managers may pause autofill in this state, which is the intended security trade-off.

Examples

With TanStack Form

Use @tanstack/react-form with zod to validate a controlled PasswordInput inside Field.Item.

API Reference

PasswordInput

The PasswordInput accepts the following props in addition to the standard HTML input attributes, except type: the toggle owns it.

PropTypeDefaultDescription
onValueVisibilityChange(visible: boolean) => voidCalled with the next visibility when the user clicks the toggle. In controlled mode, write the value back into showValue.
showValuebooleanThe controlled visibility of the value. When set, the input follows this prop; a click on the toggle only calls onValueVisibilityChange with the next value. When omitted, the toggle owns the visibility and starts hidden.
validation"error" | "success" | "warning" | false | () => "error" | "success" | "warning" | falseUse the validation prop to show if the input has a specific validation status. This will change the border and outline of the input. The false type is useful when using short-circuiting logic so that you don't need to use a ternary with undefined. Setting validation to error also sets aria-invalid.

One standard attribute is narrowed to a union, so a typo is a type error: autoComplete accepts the HTML autocomplete tokens.

Data attributes

Data AttributeValueDescription
data-slot"password-input input"The chrome around the input, joined ahead of Input's own slot.
data-slot"input-capture"The <input> element.
data-slot"password-input-toggle"The visibility toggle button.
data-disabledpresent when disabledOn the chrome. Style with data-disabled:.
data-validation"error" | "success" | "warning"On the chrome and the <input>. Omitted when unset.