--- url: "https://design-system.service.gov.uk/components/password-input" titulek: "Password input – GOV.UK Design System" h1: "Password input" popis: "Help users accessibly enter passwords" jazyk: "en" kanonicka: "https://design-system.service.gov.uk/components/password-input/" drobecky: ["Home", "Components"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 02:12:17" znaku: 19912 slov: 2967 kodovani: "utf-8" sha256: "3036ef9c42d2e8615fec2cde6220a47f1048bbce85a7fe4339543589ec865966" --- # Password input Help users to create and enter passwords. - HTML - Nunjucks HTML ```
``` Nunjucks Nunjucks macro options Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text. Some options are required for the macro to work; these are marked as “Required” in the option description. Deprecated options are marked as “Deprecated”. If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against [cross-site scripting exploits](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). Primary options string The ID of the input. Defaults to the value of `name`. string **Required.** The name of the input, which is submitted with the form data. string Optional initial value of the input. boolean If `true`, input will be disabled. string One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. object **Required.** The label used by the text input component. See macro options for label. object Can be used to add a hint to a text input component. See macro options for hint. object Can be used to add an error message to the text input component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. [See macro options for errorMessage](/components/error-message/#options-error-message-example). object Additional options for the form group containing the text input component. See macro options for formGroup. string Classes to add to the input. string Attribute to meet [WCAG success criterion 1.3.5: Identify input purpose](https://www.w3.org/WAI/WCAG22/Understanding/identify-input-purpose.html). See the [Autofill section in the HTML standard](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill) for full list of attributes that can be used. Default is `"current-password"`. object HTML attributes (for example data attributes) to add to the input. string Button text when the password is hidden. Defaults to `"Show"`. string Button text when the password is visible. Defaults to `"Hide"`. string Button text exposed to assistive technologies, like screen readers, when the password is hidden. Defaults to `"Show password"`. string Button text exposed to assistive technologies, like screen readers, when the password is visible. Defaults to `"Hide password"`. string Announcement made to screen reader users when their password has become visible in plain text. Defaults to `"Your password is visible"`. string Announcement made to screen reader users when their password has been obscured and is not visible. Defaults to `"Your password is hidden"`. object Optional object allowing customisation of the toggle button. See macro options for button. Options for `formGroup` object string Classes to add to the form group (for example to show error state for the whole group). object HTML attributes (for example data attributes) to add to the form group. object Content to add before the input used by the text input component. See macro options for formGroup beforeInput. object Content to add after the input used by the text input component. See macro options for formGroup afterInput. Options for formGroup `beforeInput` object string **Required.** Text to add before the input. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add before the input. If `html` is provided, the `text` option will be ignored. Options for formGroup `afterInput` object string **Required.** Text to add after the input. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add after the input. If `html` is provided, the `text` option will be ignored. Options for `button` object string Classes to add to the button. Options for `label` component string **Required.** If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` option will be ignored. string The value of the `for` attribute, the ID of the input the label is associated with. boolean Whether the label also acts as the heading for the page. string Classes to add to the label tag. object HTML attributes (for example data attributes) to add to the label tag. Options for `hint` component string **Required.** If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` option will be ignored. string Optional ID attribute to add to the hint span tag. string Classes to add to the hint span tag. object HTML attributes (for example data attributes) to add to the hint span tag. ``` {% from "govuk/components/password-input/macro.njk" import govukPasswordInput %} {{ govukPasswordInput({ label: { text: "Password" }, id: "password-input", name: "password" }) }} ``` ## When to use this component Use this component whenever you need users to create or enter a password. Before using this component, you should also read the guidance on the [Ask users for passwords pattern](/patterns/passwords/) and [Creating user accounts pattern](/patterns/create-accounts/). ## When not to use this component Do not use this component to ask for any information other than a password. Use a [Text input component](/components/text-input/) to ask for other security information, such as: - multi-factor authentication codes - answers to security questions - other personally identifiable information Also see the [Confirm a phone number pattern](/patterns/confirm-a-phone-number/). ## How it works This component allows users to enter a password, with an option to show what they’ve entered as plain text. This allows users to visually check their password before they submit it, which helps them reduce errors and choose passwords that are more unique and secure. ### Error messages - HTML - Nunjucks HTML ```

Error: Enter a password

``` Nunjucks Nunjucks macro options Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text. Some options are required for the macro to work; these are marked as “Required” in the option description. Deprecated options are marked as “Deprecated”. If you’re using Nunjucks macros in production with “html” options, or ones ending with “html”, you must sanitise the HTML to protect against [cross-site scripting exploits](https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting). Primary options string The ID of the input. Defaults to the value of `name`. string **Required.** The name of the input, which is submitted with the form data. string Optional initial value of the input. boolean If `true`, input will be disabled. string One or more element IDs to add to the `aria-describedby` attribute, used to provide additional descriptive information for screenreader users. object **Required.** The label used by the text input component. See macro options for label. object Can be used to add a hint to a text input component. See macro options for hint. object Can be used to add an error message to the text input component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. [See macro options for errorMessage](/components/error-message/#options-error-message-example). object Additional options for the form group containing the text input component. See macro options for formGroup. string Classes to add to the input. string Attribute to meet [WCAG success criterion 1.3.5: Identify input purpose](https://www.w3.org/WAI/WCAG22/Understanding/identify-input-purpose.html). See the [Autofill section in the HTML standard](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill) for full list of attributes that can be used. Default is `"current-password"`. object HTML attributes (for example data attributes) to add to the input. string Button text when the password is hidden. Defaults to `"Show"`. string Button text when the password is visible. Defaults to `"Hide"`. string Button text exposed to assistive technologies, like screen readers, when the password is hidden. Defaults to `"Show password"`. string Button text exposed to assistive technologies, like screen readers, when the password is visible. Defaults to `"Hide password"`. string Announcement made to screen reader users when their password has become visible in plain text. Defaults to `"Your password is visible"`. string Announcement made to screen reader users when their password has been obscured and is not visible. Defaults to `"Your password is hidden"`. object Optional object allowing customisation of the toggle button. See macro options for button. Options for `formGroup` object string Classes to add to the form group (for example to show error state for the whole group). object HTML attributes (for example data attributes) to add to the form group. object Content to add before the input used by the text input component. See macro options for formGroup beforeInput. object Content to add after the input used by the text input component. See macro options for formGroup afterInput. Options for formGroup `beforeInput` object string **Required.** Text to add before the input. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add before the input. If `html` is provided, the `text` option will be ignored. Options for formGroup `afterInput` object string **Required.** Text to add after the input. If `html` is provided, the `text` option will be ignored. string **Required.** HTML to add after the input. If `html` is provided, the `text` option will be ignored. Options for `button` object string Classes to add to the button. Options for `label` component string **Required.** If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` option will be ignored. string The value of the `for` attribute, the ID of the input the label is associated with. boolean Whether the label also acts as the heading for the page. string Classes to add to the label tag. object HTML attributes (for example data attributes) to add to the label tag. Options for `hint` component string **Required.** If `html` is set, this is not required. Text to use within the hint. If `html` is provided, the `text` option will be ignored. string **Required.** If `text` is set, this is not required. HTML to use within the hint. If `html` is provided, the `text` option will be ignored. string Optional ID attribute to add to the hint span tag. string Classes to add to the hint span tag. object HTML attributes (for example data attributes) to add to the hint span tag. ``` {% from "govuk/components/password-input/macro.njk" import govukPasswordInput %} {{ govukPasswordInput({ label: { text: "Password" }, id: "password-input-with-error-message", name: "password-input-with-error-message", errorMessage: { text: "Enter a password" } }) }} ``` If the user enters their account details incorrectly, do not reveal whether they got the username or password wrong. Clear any information entered into the password input. Revealing the source of the error can help fraudsters break into people’s accounts. See how to handle incorrect login attempts and help users who forget their password in the [Ask users for passwords pattern](/patterns/passwords/). ### Showing and hiding passwords Hide passwords by default until the user chooses to show it using the ‘show’ button. Users might not be in a private space when entering or creating a password, so you should hide passwords by default. If you do choose to include two or more password inputs on a page, the ‘show’ and ‘hide’ toggles and labels for each password input must be different. For example, you can label: - the first input as ‘Password’ with a toggle of ‘show password’ - the second input as ‘Re-enter password’ with a toggle of ‘show re-entered password’ ### Avoid adding a ‘confirm password’ field It’s not necessary to add a second password field, also known as a ‘confirm password’ field, particularly as this component allows users to show and hide passwords. See Research on this component and why we decided having a second field is not helpful for users. ### Define the input’s type as ‘password’ When the form is submitted, the password input should automatically change its `type` to `password`, if it has not already done so. This is to prevent browsers from remembering it as a previously-provided value and potentially displaying it as an autofill option on non-password inputs. ### Use the autocomplete attribute Use the `autocomplete` attribute on password inputs to help users complete forms faster. `Autocomplete` indicates to browsers and password managers what kind of password is needed so it can be entered for the user. Set the `autocomplete` attribute to `new-password` if the user is creating a password. Otherwise, use `current-password`. Many browsers will autofill password inputs, even when the `autocomplete` attribute is missing or set to `off`. ### Allow copy and paste Always allow users to copy and paste in password fields. People may have very good reasons why they want to do this, for example if they’re using a password manager. #### Copying text from password fields Users can copy any text from a password field when it’s set on ‘show’ – this is a feature of browser behaviour and cannot be overridden. This can be useful for users, such as to save a password that the browser has suggested into a separate password manager. ### Avoid restricting the user’s input See the [Ask users for passwords pattern](/patterns/passwords/) to see how to help users choose strong passwords. Support all the characters users may need to enter a password, including numbers and symbols. If you must place password restrictions on users, such as for technical or security reasons, be clear and consistent. Any restrictions must be identical wherever the user creates or enters a password. If you change the restrictions over time, you must continue to support existing user passwords or ask them to set a new one. #### Do not use maxlength to restrict password length Users will not get any feedback when they’ve reached the `maxlength` and their text input has been truncated. This happens when a user has pasted text from elsewhere or it’s been autofilled by a password manager. If you must restrict the length of a password, show an error message instead using the [Validation pattern](/patterns/validation/). ### Do not spellcheck or autocapitalise the user’s input Some browsers might automatically change what the user is typing when the input’s text is visible, such as correcting spelling or automatically turning on upper case letters at the start of sentences. You can tell browsers not to correct spellings by setting the `spellcheck` attribute to `false`. Doing this can [avoid making your service vulnerable to ‘spell-jacking’](https://www.itpro.com/security/vulnerability/370010/what-is-spell-jacking), where security researchers have found some spell checking tools gathering personal identifiable information, even user’s passwords, from password input fields to send to third party services. You can tell browsers not to autocapitalise values by setting the `autocapitalize` attribute to `off`. ### Known issues Some apps and tools will add their own native functionality to show and hide passwords. These tools include: - browsers (particularly when suggesting new passwords) - password managers - screen readers We’ve tried to minimise duplicate functionality by hiding other types of ‘show password’ buttons where possible. There’s also other instances where a password could be ‘shown’ or ‘hidden’ without the use of a button – causing a mismatch with the button label (in other words, the user would see a button to ‘show’ a password that’s already visible). [We found this mismatch happens in some browsers](https://github.com/alphagov/govuk-design-system/issues/3552#issuecomment-1976660248) when: - a keyboard shortcut is pressed - a suggested password is created ## Research on this component We [decided that having a second field is not helpful for users](https://github.com/alphagov/govuk-design-system-backlog/issues/240#issuecomment-2020125340), particularly on password inputs with show and hide buttons. However, we’d like to better support our rationale with real life examples from service teams and get your feedback. ## Recent changes | Mar 2025 | [GOV.UK Frontend v5.9.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.9.0) | The `id` parameter now defaults to match `name` if an `id` isn’t provided. | | --- | --- | --- | | May 2024 | [GOV.UK Frontend v5.4.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.4.0) | Removed duplicate `errorMessage` parameter. | | Apr 2024 | [GOV.UK Frontend v5.3.1](https://github.com/alphagov/govuk-frontend/releases/tag/v5.3.1) | Fixed issue with button size increasing if the text input has a capped width. | | Mar 2024 | [GOV.UK Frontend v5.3.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.3.0) | Component introduced. | [View full change history](/components/password-input/history/) ## Help improve this component To help make sure that this page is useful, relevant and up to date, you can: - take part in the [‘Password input’ discussion on GitHub](https://github.com/alphagov/govuk-design-system-backlog/issues/240) and share your research - [propose a change on GitHub](https://github.com/alphagov/govuk-design-system/edit/main/src/components/password-input/index.md) – read more about [how to propose changes in GitHub](/community/propose-a-content-change-using-github/) ## Need help? If you’ve got a question about the GOV.UK Design System, [contact the team](/contact/).