---
title: PasswordInput
description: "`PasswordInput` is a component that allows users to input passwords with a visibility toggle."
links:
- style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/password-input/password-input.style.ts
- source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/password-input
- storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-passwordinput--basic
---
# PasswordInput
`PasswordInput` is a component that allows users to input passwords with a visibility toggle.
```tsx
```
## Usage
```tsx
import { PasswordInput, StrengthMeter } from "@yamada-ui/react"
```
```tsx
import { PasswordInput, StrengthMeter } from "@/components/ui"
```
```tsx
import { PasswordInput, StrengthMeter } from "@workspaces/ui"
```
```tsx
```
### Change Variants
```tsx
{(variant) => (
)}
```
### Change Size
```tsx preview
{(size) => (
)}
```
### Change Color Scheme
```tsx
{(colorScheme) => (
)}
```
### Default Visible
To display the value by default, set `defaultVisible` to `true`.
```tsx
```
### Show Strength Meter
To display the strength meter, use `StrengthMeter`.
```tsx
const [value, setValue] = useState("Password")
const getStrength = (password: string): number => {
let strength = 0
if (password.length >= 8) strength++
if (/[A-Z]/.test(password)) strength++
if (/[0-9]/.test(password)) strength++
if (/[^A-Za-z0-9]/.test(password)) strength++
return strength
}
return (
setValue(e.target.value)}
/>
)
```
### Change Border Color
To change the border color, set `focusBorderColor` or `errorBorderColor` to the color.
```tsx
```
### Change Placeholder Color
To change the placeholder color, set `_placeholder` to the color.
```tsx
```
### Disable
To disable, set `disabled` to `true`.
```tsx
{(variant) => (
)}
```
### Read-Only
To make read-only, set `readOnly` to `true`.
```tsx
{(variant) => (
)}
```
### Invalid
To make invalid, set `invalid` to `true`.
```tsx
{(variant) => (
)}
```
### Customize Icon
To customize icons, set `on` and `off` of `visibilityIcon` to `ReactNode`.
```tsx
,
on: ,
}}
/>
```
### Control
```tsx
const [visible, setVisible] = useState(true)
return (
Password visibility: {visible ? "Shown" : "Hidden"}
)
```
## Props
### PasswordInput
| Prop | Default | Type | Description |
| ------------------ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| `as` | - | `As` | The HTML element to render. |
| `asChild` | - | `boolean` | Merges its props onto its immediate child. |
| `css` | - | `CSSObject \| CSSObject[]` | The CSS object. |
| `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. |
| `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. |
| `variant` | `"outline"` | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. |
| `buttonProps` | - | `PasswordInputButtonProps` | The props for the button element. |
| `defaultVisible` | `false` | `boolean` | Determines whether the password input is visible by default. |
| `elementProps` | - | `InputGroup.ElementProps` | The props for the end element. |
| `errorBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is invalid. |
| `focusBorderColor` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" ...` | The border color when the input is focused. |
| `htmlSize` | - | `number` | The native HTML `size` attribute to be passed to the `input`. |
| `invalid` | `false` | `boolean` | If `true`, the field will be invalid. |
| `onVisibleChange` | - | `(visible: boolean) => void` | Callback function that is triggered when the visibility of the password input changes. |
| `rootProps` | - | `InputGroup.RootProps` | The props for the root element. |
| `visibilityIcon` | - | `{ off: ReactNode; on: ReactNode }` | The icons to be used for the visibility toggle. |
| `visible` | `false` | `boolean` | Determines the visibility of the password input. |
### StrengthMeter
| Prop | Default | Type | Description |
| ------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| `as` | - | `As` | The HTML element to render. |
| `asChild` | - | `boolean` | Merges its props onto its immediate child. |
| `css` | - | `CSSObject \| CSSObject[]` | The CSS object. |
| `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. |
| `value` | - | `number` | The value of the password strength meter. |
| `getIndicatorProps` | - | `(percent: number) => IndicatorProps` | The props of the password strength meter indicator. |
| `max` | `4` | `number` | The maximum value of the password strength meter. |
| `withLabel` | `true` | `boolean` | If `true`, the password strength meter will display the label. |
## Accessibility
If you are not using `Field.Root`, set `aria-label` or `aria-labelledby` to `PasswordInput`.
```tsx
```
```tsx
Your password
```
### ARIA Roles and Attributes
| Element | Roles and Attributes | Usage |
| ---------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `input.ui-password-input__field` | `aria-invalid` | Set to `"true"` if `invalid` is set. |
| | `aria-disabled` | Set to `"true"` if `disabled` is set. |
| | `aria-describedby` | If `PasswordInput` is within a `Field.Root` and `Field.Root` has an `errorMessage`, `helperMessage`, or a `Field.ErrorMessage`, `Field.HelperMessage`, sets its `id`. |
| | `aria-readonly` | Set to `"true"` if `readOnly` is set. |
| | `aria-required` | Set to `"true"` if `required` is set. |
| `button.ui-password-input__button` | `aria-label` | Sets `"Toggle password visibility"`. |
| `div.ui-strength-meter__root` | `role="meter"` | Indicates that this is a meter. |
| | `aria-label` | Sets `"Password strength meter"`. |
| | `aria-valuemin` | Sets to `0`. |
| | `aria-valuemax` | Set to `max` value. |
| | `aria-valuenow` | Set to current value. |
## Similar Components
- [Editable](https://yamada-ui.com/docs/components/editable.md): `Editable` is a component used to obtain inline editable text input.
- [Input](https://yamada-ui.com/docs/components/input.md): `Input` is a component used to obtain text input from the user.
- [NumberInput](https://yamada-ui.com/docs/components/number-input.md): `NumberInput` is a component used to obtain numeric input from the user.
- [PinInput](https://yamada-ui.com/docs/components/pin-input.md): `PinInput` is a component used to capture pin codes or OTP (One-Time Password) inputs.
- [Textarea](https://yamada-ui.com/docs/components/textarea.md): `Textarea` is a component used to obtain multi-line text input.
- [FileInput](https://yamada-ui.com/docs/components/file-input.md): `FileInput` is a component used for users to select files.
- [Autocomplete](https://yamada-ui.com/docs/components/autocomplete.md): `Autocomplete` is a component used to display suggestions in response to user text input.
- [Checkbox](https://yamada-ui.com/docs/components/checkbox.md): `Checkbox` is a component used for allowing users to select multiple values from multiple options.
## Uses Components & Hooks
- [Button](https://yamada-ui.com/docs/components/button.md): `Button` is an interactive component that allows users to perform actions such as submitting forms and toggling modals.
- [Input](https://yamada-ui.com/docs/components/input.md): `Input` is a component used to obtain text input from the user.
- [Group](https://yamada-ui.com/docs/components/group.md): `Group` is a component that groups and attaches multiple elements together.
- [Icon](https://yamada-ui.com/docs/components/icon.md): `Icon` is a general icon component that can be used in your projects.
- [Field](https://yamada-ui.com/docs/components/field.md): `Field` is a component used to group form elements with label, helper message, error message, etc.