Password input
Help users accessibly enter passwords. The show and hide button appears when JavaScript runs; without it, the field is a normal password field.
Read the Design System guidance for password input
Import
import * as PasswordInput from 'govuk-react/password-input';Examples
Default
Code
<PasswordInput.Field
id="password-input"
name="password"
label="Password"
/>New password
Code
<PasswordInput.Field
id="password-input-new"
name="password"
label="Create a password"
hint="Must be at least 8 characters"
autoComplete="new-password"
/>With error message
Code
<PasswordInput.Field
id="password-input-with-error-message"
name="password"
label="Password"
errorMessage="Enter a password"
/>Welsh
Code
<PasswordInput.Field
id="password-input-cy"
name="password"
label="Cyfrinair"
showPasswordText="Datguddia"
hidePasswordText="Cuddio"
showPasswordAriaLabelText="Datgelu cyfrinair"
hidePasswordAriaLabelText="Cuddio cyfrinair"
passwordShownAnnouncementText="Mae eich cyfrinair yn weladwy"
passwordHiddenAnnouncementText="Mae eich cyfrinair wedi’i guddio"
/>With parts
Code
<PasswordInput.Root>
<label className="govuk-label" htmlFor="password-input-parts">
Password
</label>
<PasswordInput.Wrapper>
<PasswordInput.Input id="password-input-parts" name="password" />
<PasswordInput.Status />
<PasswordInput.Toggle aria-controls="password-input-parts" />
</PasswordInput.Wrapper>
</PasswordInput.Root>API reference
PasswordInput.Root
Help users accessibly enter passwords.
| Prop | Type |
|---|---|
error | boolean |
showPasswordTextButton text when the password is hidden. Defaults to | string |
hidePasswordTextButton text when the password is visible. Defaults to | string |
showPasswordAriaLabelTextButton text exposed to assistive technologies, like screen readers, when the password is hidden. Defaults to | string |
hidePasswordAriaLabelTextButton text exposed to assistive technologies, like screen readers, when the password is visible. Defaults to | string |
passwordShownAnnouncementTextAnnouncement made to screen reader users when their password has become visible in plain text. Defaults to | string |
passwordHiddenAnnouncementTextAnnouncement made to screen reader users when their password has been obscured and is not visible. Defaults to | string |
PasswordInput.Field
Help users accessibly enter passwords.
| Prop | Type |
|---|---|
labelSize | "s" | "m" | "l" | "xl" |
labelIsPageHeading | boolean |
widthA number of characters, or a fraction of the container. | 2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth |
extraLetterSpacing | boolean |
showPasswordTextButton text when the password is hidden. Defaults to | string |
hidePasswordTextButton text when the password is visible. Defaults to | string |
showPasswordAriaLabelTextButton text exposed to assistive technologies, like screen readers, when the password is hidden. Defaults to | string |
hidePasswordAriaLabelTextButton text exposed to assistive technologies, like screen readers, when the password is visible. Defaults to | string |
passwordShownAnnouncementTextAnnouncement made to screen reader users when their password has become visible in plain text. Defaults to | string |
passwordHiddenAnnouncementTextAnnouncement made to screen reader users when their password has been obscured and is not visible. Defaults to | string |
labelThe label used by the password input component. | ReactNode |
hintCan be used to add a hint to the password input component. | ReactNode |
errorMessageCan be used to add an error message to the password input component. The error message component will not display if you use a falsy value for | ReactNode |
PasswordInput.Input
| Prop | Type |
|---|---|
error | boolean |
widthA number of characters, or a fraction of the container. | 2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth |
extraLetterSpacing | boolean |
PasswordInput.Status
A visually hidden live region that announces when the password is shown or hidden.
No props of its own. Other props are passed to the element it renders.
PasswordInput.Toggle
The show and hide button. Hidden until JavaScript runs.
No props of its own. Other props are passed to the element it renders.
PasswordInput.Wrapper
No props of its own. Other props are passed to the element it renders.