Navigation
-
Back link
Use back links to help users go back to the previous page in a multi-page transaction
<div class="nhsuk-back-link">
<a class="nhsuk-back-link__link" href="#">
<svg class="nhsuk-icon nhsuk-icon__chevron-left" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" height="24" width="24">
<path d="M8.5 12c0-.3.1-.5.3-.7l5-5c.4-.4 1-.4 1.4 0s.4 1 0 1.4L10.9 12l4.3 4.3c.4.4.4 1 0 1.4s-1 .4-1.4 0l-5-5c-.2-.2-.3-.4-.3-.7z"></path>
</svg>
Go back</a>
</div>
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.
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.
Name | Type | Required | Description |
---|---|---|---|
Name text | Type string | Required false | Description Text to use within the back link component. If `html` is provided, the `text` argument will be ignored. Defaults to "Back". |
Name html | Type string | Required false | Description HTML to use within the back link component. If `html` is provided, the `text` argument will be ignored. Defaults to "Back". |
Name href | Type string | Required false | Description The value of the link href attribute. |
Name classes | Type string | Required false | Description Classes to add to the container. |
Name attributes | Type object | Required false | Description HTML attributes (for example data attributes) to add to the tag. |
Name element | Type string | Required false | Description Which html element to use to render the back link - `button` or `a`. If not provided, defaults to `a`. |
{% from 'back-link/macro.njk' import backLink %}
{{ backLink({
"href": "#",
"text": "Go back"
}) }}
When to use a back link
We only use back links on transactional services or multi-page forms.
The GOV.UK Design System recommends including a back link on question pages. Read more about question pages on GOV.UK.
You can include a back link on other pages in a multi-page transaction, if it makes sense to do so.
When not to use a back link
Do not use a back link on a content page, like a health information page.
Do not use a back link with breadcrumbs.
How to use back links
Make sure the text used in the link describes the action, for example "Go back". Carry out research with users to find the words that help them the most.
The link should take users back to the page they were on in the state they last saw it.
Consider where you put the back link. Do not put it close to other links or buttons where it might distract users from what they need to do.
The GOV.UK Design System says that you should put back links at the top of a page, but a couple of NHS services (NHS 111 online and Find out why your NHS data matters) found that it works better at the bottom of the page below the primary action. That's because we don't want to suggest to people who use a screen reader that they leave the page prematurely.
Back link as a button
You can render the back link as a button
element if necessary in order to post form data back to the previous page.
<div class="nhsuk-back-link">
<button class="nhsuk-back-link__link">
<svg class="nhsuk-icon nhsuk-icon__chevron-left" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" height="24" width="24">
<path d="M8.5 12c0-.3.1-.5.3-.7l5-5c.4-.4 1-.4 1.4 0s.4 1 0 1.4L10.9 12l4.3 4.3c.4.4.4 1 0 1.4s-1 .4-1.4 0l-5-5c-.2-.2-.3-.4-.3-.7z"></path>
</svg>
Go back</button>
</div>
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.
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.
Name | Type | Required | Description |
---|---|---|---|
Name text | Type string | Required false | Description Text to use within the back link component. If `html` is provided, the `text` argument will be ignored. Defaults to "Back". |
Name html | Type string | Required false | Description HTML to use within the back link component. If `html` is provided, the `text` argument will be ignored. Defaults to "Back". |
Name href | Type string | Required false | Description The value of the link href attribute. |
Name classes | Type string | Required false | Description Classes to add to the container. |
Name attributes | Type object | Required false | Description HTML attributes (for example data attributes) to add to the tag. |
Name element | Type string | Required false | Description Which html element to use to render the back link - `button` or `a`. If not provided, defaults to `a`. |
{% from 'back-link/macro.njk' import backLink %}
{{ backLink({
"text": "Go back",
"element": "button"
}) }}
Accessibility
When you're considering where to put back link on a page, think about people who use a screen reader.
Also, make sure the text you use describes the action. Do not rely on "Go back". It might not reflect what users expect.
Research
During testing, NHS 111 online found that some users wanted to change their answers, so they introduced a back link and labelled it to "Change my previous answer".
The Digital Accessibility Centre recommended that Find out why your NHS data matters place their back link below the primary action, because screen reader users were confused when they landed on a page and were immediately told to go back.
Have you tested this component?
If so, please share your research findings and let us know how it has worked for you. This will help us improve it for everyone.
Before you start, you will need a GitHub account. It's an open forum where we collect feedback.
If you have any questions, you can message us on Slack. You will need a Slack account if you do not have one. Or you can contact us by email.
Updated: January 2023