Skip to main content

Password Input

View as Markdown

A password field with a button that shows and hides what you typed.

Read more about installing Components and Primitives.

Nest ui:passwordInput.root in ui:field.root. The password input takes name, required, disabled, invalid and aria-describedby from the field. Set autoComplete to new-password, so the browser offers to generate a strong password. Type fewer than 12 characters in the demo and leave the input to see the error.

At least 12 characters.

Set ignorePasswordManagers="{true}" for a password that is not the visitor's own login, like the guest Wi-Fi password in the demo. 1Password, LastPass, Bitwarden, Dashlane and Proton Pass then leave the input alone. defaultVisible="{true}" shows the password when the page loads.

Put one passwordInput.indicator per state into the visibility trigger. The one matching the current state is shown.

The labels of the visibility trigger ship in the language file and follow the site language. Pass translations to override them for one password input: visibilityTriggerLabelHidden is read while the password is hidden ("Show password"), visibilityTriggerLabelVisible while it is shown.

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

Provides shared password input state and wraps all related parts. Renders a <div> element.

NameDescriptionRequiredDefault
disabledboolean
Whether the password input is disabled. Inherited from a surrounding field when available.
No
-
invalidboolean
Whether the password input value is invalid. Inherited from a surrounding field when available.
No
-
requiredboolean
Whether the password input is required. Inherited from a surrounding field when available.
No
-
readOnlyboolean
Whether the password input is readonly. Inherited from a surrounding field when available.
No
-
namestring
The name attribute of the password input. Useful for form submission. Inherited from a surrounding field when available.
No
-
defaultVisibleboolean
Whether the password is shown as plain text when rendered.
No
false
autoCompleteEnum\PasswordAutoComplete
The autocomplete attribute of the input. Use `new-password` on a sign-up or change-password form, so the browser offers to generate a password.
No
CurrentPassword
ignorePasswordManagersboolean
Whether password managers leave the input alone. Works for 1Password, LastPass, Bitwarden, Dashlane and Proton Pass.
No
false
translationsarray
Localized labels of the visibility trigger, `visibilityTriggerLabelHidden` and `visibilityTriggerLabelVisible`. A client script can pass a `visibilityTrigger` function of the visible state instead. Use `f:translate` for per-template localization overrides when needed.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
providerstring
The `id` of the `.provider` this root takes its `rootId` and props from.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-password-input-root<uid>
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only

Labels the password input. Renders a <label> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-password-input-label<uid>
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only
data-requiredPresent when required

Groups the input and the visibility trigger. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-password-input-control<uid>
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only

Provides the password input. Renders an <input> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-password-input-input<uid>
data-state"visible" | "hidden"
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only

Shows or hides the password. Renders a <button> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-password-input-visibility-trigger<uid>
data-readonlyPresent when read-only
data-disabledPresent when disabled
data-state"visible" | "hidden"

Shows content for one visibility state. Renders a <span> element.

NameDescriptionRequiredDefault
stateEnum\PasswordInputIndicatorState
The visibility state the indicator is shown in.
Yes
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-password-input-indicator<uid>
data-state"visible" | "hidden"
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only
NameTypeDescription
visiblebooleanWhether the password input is visible.
disabledbooleanWhether the password input is disabled.
invalidbooleanWhether the password input is invalid.
focusVoidFunctionFocus the password input.
setVisible(value: boolean) => voidSet the visibility of the password input.
toggleVisibleVoidFunctionToggle the visibility of the password input.
getRootState() => RootStateReturns the state of the root.
getInputState() => InputStateReturns the state of the input.
getVisibilityTriggerState() => VisibilityTriggerStateReturns the state of the visibility trigger.