---
title: "Password Field"
description: "A password field with an eye button that shows or hides the text, and a hint when Caps Lock is on. It hides the password again on submit."
url: https://gelatinui.com/components/password-field
markdown_url: https://gelatinui.com/components/password-field.md
access: free
install: "npx shadcn@latest add @gelatin-ui/password-field"
registry_item: https://gelatinui.com/r/password-field.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Password Field

> A password field with an eye button that shows or hides the text, and a hint when Caps Lock is on. It hides the password again on submit.

Page: https://gelatinui.com/components/password-field

## When to use it

Best for: A password input with a show and hide toggle that goes back to hidden on submit, page hide, and unmount.

- Use it for each password in a sign-in, sign-up, or change form.
- Use `PasswordFieldToggle` so people can check what they typed.
- Use `PasswordFieldCapsLock` in the same `Field` to show a Caps Lock hint.

## When not to use it

- For a one-time code, use an [Input OTP](https://gelatinui.com/components/input-otp.md).
- To show how strong a new password is, add a [Password Strength](https://gelatinui.com/components/password-strength.md).

## Notes for agents

- Pass `autoComplete="new-password"` on a sign-up or change form. The default is `current-password`.
- The field goes back to hidden on form submit, page hide, and unmount. `onVisibleChange` runs for each change.
- The toggle name stays "Show password" in both states and it uses `aria-pressed`. Do not swap the name.
- The toggle is disabled with the input, so Tab skips it in a disabled field.
- `PasswordFieldCapsLock` watches the closest `Field`, else its parent. Put it in the same `Field`.
- Every `InputGroup` prop passes, such as `size`.

## Anatomy

```text
PasswordField
├─ PasswordFieldInput (0..n)
├─ PasswordFieldToggle (0..n)
└─ PasswordFieldCapsLock (0..n)
```

## API reference

### PasswordField

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default"` |  |  |
| `className` | `string` |  |  |
| `visible` | `boolean` |  | Shows the password as text (controlled). |
| `defaultVisible` | `boolean` | false | Shows the password as text at first (uncontrolled). Default `false`. |
| `onVisibleChange` | `function` |  | Runs when the toggle, a form submit, or a page hide changes `visible`. |

### PasswordFieldInput

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` |  |  |

Also takes every prop of Base UI `Input`: https://base-ui.com/react/components/input

### PasswordFieldToggle

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `size` | `"icon-sm" \| "icon-xs" \| "sm" \| "xs"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` |  |  |
| `label` | `string` | "Show password" | The name of the toggle. Default "Show password". It does not change with the state. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### PasswordFieldCapsLock

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| PasswordField | `password-field` |  |  |  |
| PasswordFieldInput | `password-field-input` |  |  |  |
| PasswordFieldToggle | `password-field-toggle` | `aria-pressed` |  |  |
| PasswordFieldCapsLock | `password-field-caps-lock` |  |  |  |

## Usage

Put `PasswordFieldInput` and `PasswordFieldToggle` in `PasswordField`, inside a `Field`. Pass `autoComplete="new-password"` on a sign-up form.

The sample also uses `field`, which this add does not write. One command adds them with this item:

```bash
npx shadcn@latest add @gelatin-ui/password-field @gelatin-ui/field
```

```tsx title="sign-in-password.tsx"
import { Field, FieldLabel } from "@/components/ui/field";
import {
  PasswordField,
  PasswordFieldCapsLock,
  PasswordFieldInput,
  PasswordFieldToggle,
} from "@/components/ui/password-field";

export function SignInPassword() {
  return (
    <Field name="password">
      <FieldLabel>Password</FieldLabel>
      <PasswordField>
        <PasswordFieldInput />
        <PasswordFieldToggle />
      </PasswordField>
      <PasswordFieldCapsLock />
    </Field>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/password-field
```

It adds 23 registry items: 20 files, 3083 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@phosphor-icons/react`, `clsx`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Input Group](https://gelatinui.com/components/input-group.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Password Strength](https://gelatinui.com/components/password-strength.md)
- [Input Group](https://gelatinui.com/components/input-group.md)
- [Animated Eye Icon](https://gelatinui.com/components/animated-eye-icon.md)
- [Input](https://gelatinui.com/components/input.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Enter, Space | On `PasswordFieldToggle`: shows or hides the password. Focus stays on the toggle. |

## Accessibility

The toggle name stays "Show password" in both states, and it uses `aria-pressed`.

The field goes back to hidden on submit, page hide, and unmount, so a browser never keeps a shown password.

The toggle is disabled with the input, so Tab skips it in a disabled field.
