Service navigation
Service navigation helps users understand that they’re using your service and lets them navigate around your service.
With only a service name
The Design System recommendation is to display the service name in the service navigation instead of in the header. On basic services this means the service navigation can be rendered without any navigation links.
Input
= govuk_service_navigation(service_name: "My new service", service_url: "#")<%= govuk_service_navigation(service_name: "My new service", service_url: "#") %>Output
<section aria-label="Service information" class="govuk-service-navigation" data-module="govuk-service-navigation">
<div class="govuk-width-container">
<div class="govuk-service-navigation__container"><span class="govuk-service-navigation__service-name"><a class="govuk-service-navigation__link" href="#">My new service</a></span></div>
</div>
</section>With navigation items
Show navigation links to let users navigate to different parts of your service and find useful links and tools.
When you are on the linked page you can use current: true to mark it. If
you’re on a page within the section but not on the page itself, use
active: true instead.
Automatically detecting the current page
Having to work out which page is current and adjust the parameters manually
would be complicated. If you pass in the current_path, when navigation
nodes that have a matching href are rendered, they’ll be rendered as
the current page.
Input
= govuk_service_navigation(service_name: "My new service",
current_path: "/components/panel",
navigation_items: navigation_items,
navigation_id: 'example-3')<%= govuk_service_navigation(service_name: "My new service", current_path: "/components/panel", navigation_items: navigation_items, navigation_id: 'example-3') %>{ navigation_items: [
{ text: "Footer", href: "/components/footer" },
{ text: "Header", href: "/components/header" },
{ text: "Panel", href: "/components/panel" },
{ text: "Table", href: "/components/table" },
{ text: "Tag", href: "/components/tag" }
] }Output
<section aria-label="Service information" class="govuk-service-navigation" data-module="govuk-service-navigation">
<div class="govuk-width-container">
<div class="govuk-service-navigation__container"><span class="govuk-service-navigation__service-name"><span class="govuk-service-navigation__text">My new service</span></span><nav aria-label="Menu" class="govuk-service-navigation__wrapper"><button type="button" class="govuk-service-navigation__toggle govuk-js-service-navigation-toggle" aria-controls="example-3" aria-hidden="true" hidden="hidden">Menu</button>
<ul id="example-3" class="govuk-service-navigation__list">
<li class="govuk-service-navigation__item"><a class="govuk-service-navigation__link" href="/components/footer">Footer</a></li>
<li class="govuk-service-navigation__item"><a class="govuk-service-navigation__link" href="/components/header">Header</a></li>
<li class="govuk-service-navigation__item govuk-service-navigation__item--active"><strong class="govuk-service-navigation__active-fallback"><a class="govuk-service-navigation__link" aria-current="page" href="/components/panel">Panel</a></strong></li>
<li class="govuk-service-navigation__item"><a class="govuk-service-navigation__link" href="/components/table">Table</a></li>
<li class="govuk-service-navigation__item"><a class="govuk-service-navigation__link" href="/components/tag">Tag</a></li>
</ul>
</nav></div>
</div>
</section>Automatic active page matching
Often we have pages deeply nested within sections of the site and want
the navigation to show which section we’re currently in. We can do this
using active_when.
When active_when is a string the component will check if the beginning of
the current_path matches it. For more complex scenarios a regular expression
can be used instead.
Input
= govuk_service_navigation(service_name: "My new service",
current_path: "/components/table/dining/extendable",
navigation_items: navigation_items,
navigation_id: 'example-4')<%= govuk_service_navigation(service_name: "My new service", current_path: "/components/table/dining/extendable", navigation_items: navigation_items, navigation_id: 'example-4') %>{ navigation_items: [
{ text: "Footer", href: "/components/footer", active_when: "/components/footer" },
{ text: "Header", href: "/components/header", active_when: "/components/header" },
{ text: "Panel", href: "/components/panel", active_when: "/components/panel" },
{ text: "Table", href: "/components/table", active_when: "/components/table" },
{ text: "Tag", href: "/components/tag", active_when: "/components/tag" }
] }Output
<section aria-label="Service information" class="govuk-service-navigation" data-module="govuk-service-navigation">
<div class="govuk-width-container">
<div class="govuk-service-navigation__container"><span class="govuk-service-navigation__service-name"><span class="govuk-service-navigation__text">My new service</span></span><nav aria-label="Menu" class="govuk-service-navigation__wrapper"><button type="button" class="govuk-service-navigation__toggle govuk-js-service-navigation-toggle" aria-controls="example-4" aria-hidden="true" hidden="hidden">Menu</button>
<ul id="example-4" class="govuk-service-navigation__list">
<li class="govuk-service-navigation__item"><a class="govuk-service-navigation__link" href="/components/footer">Footer</a></li>
<li class="govuk-service-navigation__item"><a class="govuk-service-navigation__link" href="/components/header">Header</a></li>
<li class="govuk-service-navigation__item"><a class="govuk-service-navigation__link" href="/components/panel">Panel</a></li>
<li class="govuk-service-navigation__item govuk-service-navigation__item--active"><strong class="govuk-service-navigation__active-fallback"><a class="govuk-service-navigation__link" aria-current="true" href="/components/table">Table</a></strong></li>
<li class="govuk-service-navigation__item"><a class="govuk-service-navigation__link" href="/components/tag">Tag</a></li>
</ul>
</nav></div>
</div>
</section>Inverting the service navigation colour
Use inverse: true to render the service navigation component with white links on a blue background.
Adding items to the start and end of the navigation
For extra customisation the service navigation can be assembled manually. We can
use the navigation_start and navigation_end to add custom HTML at the beginning and
end of the service navigation.
Adding content above and below the service navigation
To add extra content above and below the service navigation use the content_before
and content_after slots. This HTML will be unstyled, you must provide your own styles
and JavaScript for the custom HTML.
Placing items on the right of the service navigation
If there’s enough space, you can render the content_after block on the
right of the navigation by passing inline: true.