A text field for entering a password, with a button that shows or hides what was typed.
Import
import { PasswordInput } from "@kobalte/core/password-input";// orimport { Root, Label, Input, VisibilityTrigger, Indicator, ... } from "@kobalte/core/password-input";Features
- Built on
TextField, so labelling, description, error message, validation and form submission behave the same. PasswordInput.Inputswitches itstypebetweenpasswordandtext, and defaults toautocomplete="current-password",spellcheck="false"andautocapitalize="off".PasswordInput.VisibilityTriggeris a toggle button: it exposes its state witharia-pressed, points at the input witharia-controls, and keeps a fixedaria-labelso screen readers announce "Show password, toggle button, pressed/not pressed".- Pressing the trigger with a pointer keeps focus and the caret in the input.
- Can be controlled or uncontrolled, for both the value and the visibility.
- Renders
type="password"on the server, so the password is never shown before hydration.
Anatomy
The password input consists of:
- PasswordInput: The root container for the password input.
- PasswordInput.Label: The label that gives the user information on the password input.
- PasswordInput.Input: The native HTML input of the password input.
- PasswordInput.VisibilityTrigger: The button that toggles the visibility of the password.
- PasswordInput.Indicator: Renders different content depending on the visibility, typically an eye icon.
- PasswordInput.Description: The description that gives the user more information on the password input.
- PasswordInput.ErrorMessage: The error message that gives the user information about how to fix a validation error on the password input.
<PasswordInput> <PasswordInput.Label /> <PasswordInput.Input /> <PasswordInput.VisibilityTrigger> <PasswordInput.Indicator /> </PasswordInput.VisibilityTrigger> <PasswordInput.Description /> <PasswordInput.ErrorMessage /></PasswordInput>Example
export function BasicExample() { return ( <PasswordInput class={style["password-input"]}> <PasswordInput.Label class={style["password-input__label"]}> Password </PasswordInput.Label> <div class={style["password-input__control"]}> <PasswordInput.Input class={style["password-input__input"]} /> <PasswordInput.VisibilityTrigger class={style["password-input__trigger"]} > <PasswordInput.Indicator fallback={<EyeOffIcon />}> <EyeIcon /> </PasswordInput.Indicator> </PasswordInput.VisibilityTrigger> </div> </PasswordInput> );.password-input { display: flex; flex-direction: column; gap: 4px;}
.password-input__label { color: hsl(240 6% 10%); font-size: 14px; font-weight: 500; user-select: none;}
.password-input__control { position: relative; display: inline-flex; width: 240px;}
.password-input__input { width: 100%; border-radius: 6px; padding: 6px 40px 6px 12px; font-size: 16px; outline: none; background-color: white; border: 1px solid hsl(240 6% 90%); color: hsl(240 4% 16%); transition: border-color 250ms, color 250ms;}
.password-input__input:hover { border-color: hsl(240 5% 65%);}
.password-input__input:focus-visible { outline: 2px solid hsl(200 98% 39%); outline-offset: 2px;}
.password-input__input[data-invalid] { border-color: hsl(0 72% 51%); color: hsl(0 72% 51%);}
.password-input__input[data-disabled] { opacity: 0.5;}
.password-input__trigger { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: none; border-radius: 4px; background: transparent; color: hsl(240 4% 46%); cursor: pointer;}
.password-input__trigger:hover { color: hsl(240 6% 10%); background-color: hsl(240 5% 96%);}
.password-input__trigger:focus-visible { outline: 2px solid hsl(200 98% 39%); outline-offset: 1px;}
.password-input__trigger[data-disabled] { opacity: 0.5; cursor: not-allowed;}
.password-input__description { color: hsl(240 5% 26%); font-size: 12px; user-select: none;}
.password-input__error-message { color: hsl(0 72% 51%); font-size: 12px; user-select: none;}
[data-theme*="dark"] .password-input__label { color: hsl(240 5% 84%);}
[data-theme*="dark"] .password-input__input { background-color: hsl(240 4% 16%); border: 1px solid hsl(240 5% 34%); color: hsl(0 100% 100% / 0.9);}
[data-theme*="dark"] .password-input__input:hover { border-color: hsl(240 4% 46%);}
[data-theme*="dark"] .password-input__input[data-invalid] { border-color: hsl(0 72% 51%); color: hsl(0 72% 51%);}
[data-theme*="dark"] .password-input__trigger { color: hsl(240 5% 65%);}
[data-theme*="dark"] .password-input__trigger:hover { color: hsl(0 100% 100% / 0.9); background-color: hsl(240 5% 26%);}
[data-theme*="dark"] .password-input__description { color: hsl(240 5% 65%);}EyeIcon and EyeOffIcon stand for any icon components.
Usage
Controlled visibility
The visible prop controls whether the password is shown. Use it with onVisibleChange to keep your own state in sync. defaultVisible sets the initial visibility when the component is uncontrolled.
The password is hidden.
import { PasswordInput } from "@kobalte/core/password-input";import { createSignal } from "solid-js";
function ControlledExample() { const [visible, setVisible] = createSignal(false);
return ( <> <PasswordInput visible={visible()} onVisibleChange={setVisible}> <PasswordInput.Label>Password</PasswordInput.Label> <PasswordInput.Input /> <PasswordInput.VisibilityTrigger> <PasswordInput.Indicator fallback={<EyeOffIcon />}> <EyeIcon /> </PasswordInput.Indicator> </PasswordInput.VisibilityTrigger> </PasswordInput> <p>The password is {visible() ? "visible" : "hidden"}.</p> </> );}New password
PasswordInput.Input defaults to autocomplete="current-password". On sign-up or password change forms, set autocomplete="new-password" so password managers offer to generate one.
<PasswordInput> <PasswordInput.Label>New password</PasswordInput.Label> <PasswordInput.Input autocomplete="new-password" /> <PasswordInput.VisibilityTrigger> <PasswordInput.Indicator fallback={<EyeOffIcon />}> <EyeIcon /> </PasswordInput.Indicator> </PasswordInput.VisibilityTrigger> <PasswordInput.Description>Use at least 12 characters.</PasswordInput.Description></PasswordInput>Error message
The PasswordInput.ErrorMessage component shows an error message when the password input is invalid.
import { PasswordInput } from "@kobalte/core/password-input";import { createSignal } from "solid-js";
function ErrorMessageExample() { const [value, setValue] = createSignal("1234");
return ( <PasswordInput value={value()} onChange={setValue} validationState={value().length < 8 ? "invalid" : "valid"} > <PasswordInput.Label>Password</PasswordInput.Label> <PasswordInput.Input /> <PasswordInput.VisibilityTrigger> <PasswordInput.Indicator fallback={<EyeOffIcon />}> <EyeIcon /> </PasswordInput.Indicator> </PasswordInput.VisibilityTrigger> <PasswordInput.ErrorMessage> Your password must be at least 8 characters long. </PasswordInput.ErrorMessage> </PasswordInput> );}Disabled
A disabled password input also disables its visibility trigger.
API Reference
PasswordInput
PasswordInput is equivalent to the Root import from @kobalte/core/password-input.
| Prop | Description |
|---|---|
| visible | boolean Whether the password is shown as plain text (controlled). |
| defaultVisible | boolean Whether the password is shown as plain text when initially rendered. Useful when you do not need to control the visibility. |
| onVisibleChange | (visible: boolean) => void Event handler called when the visibility of the password changes. |
| translations | PasswordInputIntlTranslations Localization strings. |
| value | string The controlled value of the password input. |
| defaultValue | string The default value when initially rendered. Useful when you do not need to control the value. |
| onChange | (value: string) => void Event handler called when the value of the password input changes. |
| name | string The name of the password input, used when submitting an HTML form. See MDN. |
| validationState | 'valid' | 'invalid' Whether the password input should display its "valid" or "invalid" visual styling. |
| required | boolean Whether the user must fill the password input before the owning form can be submitted. |
| disabled | boolean Whether the password input is disabled. Also disables the visibility trigger. |
| readOnly | boolean Whether the password input can be selected but not changed by the user. |
| Data attribute | Description |
|---|---|
| data-visible | Present when the password is shown as plain text. |
| data-valid | Present when the password input is valid according to the validation rules. |
| data-invalid | Present when the password input is invalid according to the validation rules. |
| data-required | Present when the user must fill the password input before the owning form can be submitted. |
| data-disabled | Present when the password input is disabled. |
| data-readonly | Present when the password input is read only. |
PasswordInput.Label, PasswordInput.Input, PasswordInput.Description and PasswordInput.ErrorMessage share the same validation data-attributes. PasswordInput.Input, PasswordInput.VisibilityTrigger and PasswordInput.Indicator also get data-visible.
PasswordInput.Input
Renders type="password" while hidden and type="text" while visible. Any prop can be overridden.
| Prop | Description |
|---|---|
| autocomplete | string Defaults to "current-password". Use "new-password" on sign-up. |
| spellcheck | "true" | "false" Defaults to "false". |
| autocapitalize | string Defaults to "off". |
PasswordInput.VisibilityTrigger
Toggles the visibility on click. Its aria-label comes from translations.visibilityTrigger ("Show password") unless you pass your own, and it stays the same in both states: aria-pressed carries the state.
| Data attribute | Description |
|---|---|
| data-visible | Present when the password is shown as plain text. |
| data-disabled | Present when the password input is disabled. |
PasswordInput.Indicator
| Prop | Description |
|---|---|
| children | JSX.Element The content rendered while the password is visible. |
| fallback | JSX.Element The content rendered while the password is hidden. |
The indicator is rendered with aria-hidden="true"; the trigger provides the accessible name.
PasswordInput.ErrorMessage
| Prop | Description |
|---|---|
| forceMount | boolean Used to force mounting when more control is needed. Useful when controlling animation with SolidJS animation libraries. |
Rendered elements
| Component | Default rendered element |
|---|---|
PasswordInput | div |
PasswordInput.Label | label |
PasswordInput.Input | input |
PasswordInput.VisibilityTrigger | button |
PasswordInput.Indicator | span |
PasswordInput.Description | div |
PasswordInput.ErrorMessage | div |
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
Tab | Moves focus between the input and the visibility trigger. |
Space | When focus is on the visibility trigger, toggles the visibility. |
Enter | When focus is on the visibility trigger, toggles the visibility. |
Last updated: 12/4/26, 3:58 PM