Skip to main content
Components

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.

PropType
errorboolean
showPasswordText

Button text when the password is hidden. Defaults to "Show".

string
hidePasswordText

Button text when the password is visible. Defaults to "Hide".

string
showPasswordAriaLabelText

Button text exposed to assistive technologies, like screen readers, when the password is hidden. Defaults to "Show password".

string
hidePasswordAriaLabelText

Button text exposed to assistive technologies, like screen readers, when the password is visible. Defaults to "Hide password".

string
passwordShownAnnouncementText

Announcement made to screen reader users when their password has become visible in plain text. Defaults to "Your password is visible".

string
passwordHiddenAnnouncementText

Announcement made to screen reader users when their password has been obscured and is not visible. Defaults to "Your password is hidden".

string

PasswordInput.Field

Help users accessibly enter passwords.

PropType
labelSize"s" | "m" | "l" | "xl"
labelIsPageHeadingboolean
width

A number of characters, or a fraction of the container.

2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth
extraLetterSpacingboolean
showPasswordText

Button text when the password is hidden. Defaults to "Show".

string
hidePasswordText

Button text when the password is visible. Defaults to "Hide".

string
showPasswordAriaLabelText

Button text exposed to assistive technologies, like screen readers, when the password is hidden. Defaults to "Show password".

string
hidePasswordAriaLabelText

Button text exposed to assistive technologies, like screen readers, when the password is visible. Defaults to "Hide password".

string
passwordShownAnnouncementText

Announcement made to screen reader users when their password has become visible in plain text. Defaults to "Your password is visible".

string
passwordHiddenAnnouncementText

Announcement made to screen reader users when their password has been obscured and is not visible. Defaults to "Your password is hidden".

string
label

The label used by the password input component.

ReactNode
hint

Can be used to add a hint to the password input component.

ReactNode
errorMessage

Can 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 errorMessage, for example false or null.

ReactNode

PasswordInput.Input

PropType
errorboolean
width

A number of characters, or a fraction of the container.

2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth
extraLetterSpacingboolean

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.