Skip link
Use a skip link to help keyboard-only users skip to the main content on a page.
<p class="hs2-body">To view the skip link, tab to this example, or click inside this example and press tab.</p>
<a class="hs2-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="hs2-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 HS2.org.uk pages must include a skip link in the header following guidance in the GOV.UK Design System.
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 component is visually hidden until a keyboard press activates it.