Skip to content

Password Field

A password input with a toggle that reveals the typed value.

hero.tsx

Usage guidelines

  • Use PasswordField for a password the user types and may reveal to check. It renders the InputGroup surface, so its border, focus, invalid and disabled visuals match every other grouped input.
  • Set autoComplete on PasswordFieldInput; the types require it. Use current-password for an existing password and new-password for a password being set, so password managers fill or suggest the right value. PasswordFieldInput owns type.
  • Wrap the field in Field with a FieldLabel for the label, validation and errors.
  • PasswordFieldToggle is optional. Give it an aria-label that stays the same in both states; aria-pressed reports whether the value is revealed. It is a type="button" button, so it never submits the form. Pressing it with a pointer keeps focus in the input, and it stays available while the input is read-only.
  • Set disabled on PasswordField to disable both the input and the toggle, and on the surrounding Field so FieldLabel receives data-disabled as well. A disabled Field alone reaches only the input.
  • Keep PasswordField for the user's own account password. Credentials for other services, such as API keys, tokens and database passwords, use Input with type="password" and autoComplete="off": current-password invites the browser to fill the account password into them, and new-password makes it suggest a generated one. Some password managers ignore autoComplete="off" on masked inputs, so keep these fields out of sign-in and password forms.
  • Ask for a new password once. The reveal toggle lets the user check what they typed, so a second "confirm password" input is unnecessary.

Anatomy

tsx
tsx

The anatomy mirrors the upstream Base UI Password Field preview. The reveal behavior is a local implementation until Base UI ships the primitive; the parts then wrap it without changing call sites.

Examples

In a form

A password change form asks for the current password and one new password. A hidden username input tells password managers which account the new password belongs to. Native constraints and validate drive the field errors, which appear when the form is submitted and then update as the value changes. The submit button shows loading while the request runs and ignores repeated submits. A rejected current password comes back through Form errors and shows in the FieldError without match; enter incorrect as the current password to see it.

At least 8 characters.

form.tsx

Read-only and disabled

A read-only temporary password can still be revealed. Setting disabled on both Field and PasswordField disables the label, input and toggle together, and the description says why.

Share it with the new member. It expires in 24 hours.

Your workspace requires single sign-on.

states.tsx

Tokens and API keys

A model provider key is masked with Input and type="password". autoComplete="off" asks the browser not to fill a saved password into it or suggest a generated one.

Stored encrypted and used only for this workspace.

token.tsx

Keyboard

KeyAction
TabMoves focus from the input to the toggle.
EnterorSpaceReveals or masks the value when the toggle has focus.

API reference

PasswordField

A compound password input with a built-in visibility toggle on the InputGroup surface. Renders a <div> element.

Props
PropTypeDefaultDetails
disabledbooleanfalse

PasswordFieldInput

The password input inside PasswordField; requires autoComplete ('current-password' or 'new-password'). Renders an <input> element.

Base UI Input docs

Props
PropTypeDefaultDetails
autoComplete required'current-password' | 'new-password'No default
Base UI Input docs
Data attributes
AttributeDescription
data-disabled

Present when the input is disabled.

data-valid

Present when the input is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the input is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the input has been touched (when wrapped in Field.Root).

data-dirty

Present when the input's value has changed (when wrapped in Field.Root).

data-filled

Present when the input is filled (when wrapped in Field.Root).

data-focused

Present when the input is focused (when wrapped in Field.Root).

PasswordFieldToggle

An inline-end add-on containing an icon button that toggles password visibility; requires aria-label. Renders a <div> element containing a <button>.

Props
PropTypeDefaultDetails
aria-label requiredstringNo default
disabledbooleanfalse