Skip link
Use a skip link to help keyboard-only users skip to the main content on a page.
<p class="hse-body">To view the skip link, tab to this example, or click inside this example and press tab.</p>
<a class="hse-skip-link" href="#maincontent">Skip to main content</a>
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 skip link component. Defaults to `Skip to main content` if you do not provide a value. |
Name href | Type string | Required false | Description The value of the skip link’s `href` attribute. Defaults to `#maincontent` if you do not provide a value. |
Name classes | Type string | Required false | Description Classes to add to the skip link. |
Name attributes | Type object | Required false | Description HTML attributes (for example data attributes) to add to the skip link. |
<p class="hse-body">To view the skip link, tab to this example, or click inside this example and press tab.</p>
{% from 'skip-link/macro.njk' import skipLink %}
{{ skipLink({
"href": "#maincontent",
"text": "Skip to main content"
}) }}
When to use a skip link
All HSE pages must include a skip link in the header.
Usually, you should put the skip link immediately after the opening body tag. However, if you’re using a cookie banner, place the skip link immediately after the cookie banner.
Some automated accessibility testing tools may warn that the skip link element is not inside a landmark. This warning does not apply to skip links, so you can ignore it.
Do not wrap the skip link in a nav region, or move it inside the header.
How skip links work
Some people use the tab key on their keyboard to navigate through the links and form elements on a web page. Including a skip link gives users the option to bypass the top-level navigation links and jump to the main content on the page.
The skip link is visually hidden until a keyboard press activates it.
Research
If you’ve used skip links, please share your user research findings.
Updated: August 2023