Vanilla includes a simple navigation bar that you can add to the top of your sites.
The navigation items are collapsed behind a "Menu" link in small screens and displayed horizontally on larger screens.
Note:By default, the width of the navigation is constrained to
$grid-max-width. To make the navigation full width, replace
The navigation pattern is one of the first patterns to implement the new theming architecture in Vanilla. The default is light. But, to switch to a dark navigation, you can either:
- Override the value of the
- Add a state class to the
is-darkwhen the default navigation is light, or
is-lightwhen the default has been changed to dark
You can also manually override the background color of the navigation using the variable
$color-navigation-background. If the lightness of the background is above 70%, the text colour will switch to dark to improve readability.
You can change the breakpoint at which the menu changes to a small screen menu
by adjusting the
In Vanilla 2.8 we deprecated the use of
p-navigation__link and classless
<a> in the navigation. Support for these classes will be removed in future version 3.0.
You should use
<a class="p-navigation__link"> instead.
To update to new class names:
- rename all occurrences of
- rename all occurrences of
p-navigation__linkclass to all
<a>elements that are direct child of
Drop-down menus can be added to the navigation by including one or more
To open the dropdown you need to set the
is-active class on
p-navigation__item--dropdown-toggle element, but also set
By default, dropdowns are left-aligned with their parent; if you'd prefer the menu to be positioned from the right, use the
p-navigation__dropdown--right modifier. This can be seen in the "My account" menu in the example.
.p-subnav is now deprecated, it and its associated child elements can be updated simply by substituting the following class names:
|Deprecated classes||Replaced by|
The side navigation pattern can be used to provide more detailed navigation alongside your content.
It allows grouping the links into navigation sections and nesting them up to three levels.
Current page in the side navigation should be highlighted by adding
aria-current="page" attribute to the corresponding
p-side-navigation__link element. Alternatively, if
aria-current attribute cannot be set, the
is-active class can be used instead.
p-side-navigation__link elements to add status labels or icons on right side of navigation items.
To add icons on the left side of the items in side navigation use the
Note:Icons should only be used on the items in the first level of side navigation.
On pages with content significantly longer than the side navigation contents you can make the navigation sticky to keep it visible when scrolling by adding
.is-sticky class to the root element of
Breaking change:Side navigation used to be sticky by default, but since Vanilla 2.21.0
.is-sticky class is needed to add this functionality.
When the HTML markup of the side navigation links is generated by an external service and Vanilla class names cannot be added to the elements, use the
In this variant, the side navigation pattern will style headings (
h3, etc.) and lists (
li) with links or text elements (
span) consistently with default side navigation component:
- headings (
h3, etc.) get the styling of
ultags are styled as
- nesting lists (
ul > li > ul > li ...) is possible up to 3 levels
- nesting lists (
- text elements (
liare styled as
- links (
liare styled as
is-activeclass needs to be added to a link element to mark the active page
Because of the limitations of raw HTML markup without class names, it's not possible to use icons or status labels in the raw HTML variant of side navigation.
Do:Use the raw HTML variant when the backend serving the navigation content won't allow custom class names on HTML elements.
Don't:Use raw HTML variant when the markup can be fully controlled and class names can be properly added to all elements.
On small screens side navigation is rendered off-screen as a drawer. To open the side navigation drawer, add
is-expanded class to
.p-side-navigation element. To close the drawer (with the animation) remove
is-expanded class and replace it with
href attribute pointing to the
id attribute of the side navigation element (for example:
<a href="#drawer" class="p-side-navigation__toggle">).
For applications built with the application layout the size and positioning of the navigation panel is handled by the layout itself, so the side navigation component doesn't need it's own drawer, overlay or toggle buttons.
To use side navigation in the application place
.p-side-navigation--icons in the
l-navigation element. You don't use
p-side-navigation__drawer elements, just put the lists of the links
p-side-navigation__list as direct children of
Additionally, in order for application layout to fully control side navigation elements when expanding and collapsing you need to wrap the text of the side navigation items in
<span class="p-side-navigation__label">. This will allow to fade them out when navigation collapses.
For more information, read the dedicated application layout documentation.
The side navigation is available in a light and a dark theme. The colours used by both themes in the colour settings file. Overriding the colours of individual elements of the side navigation is discouraged, as this may lead to accessibility issues, or inconsistencies with other components that use the same theme.
By default, the side navigation uses the light theme. To change the global default, set
To change the appearance of an individual instance of the side navigation, you can use the
For more details about themes in Vanilla refer to the Color theming section of the documentation.
To import just navigation or sub-navigation component into your project, copy snippets below and include it in your main Sass file.
// import Vanilla and include base mixins // this only needs to happen once in a given project @import 'vanilla-framework/scss/vanilla'; @include vf-base; @include vf-p-navigation; // sub-navigation is optional you can include it alongside navigation component @include vf-p-subnav;
To import side navigation, copy snippet below:
// import Vanilla and include base mixins // this only needs to happen once in a given project @import 'vanilla-framework/scss/vanilla'; @include vf-base; @include vf-p-side-navigation; // optionally add icons and/or labels if you use them in side navigation__nav @include vf-p-label; @include vf-p-icons;
For more information see Customising Vanilla in your projects, which includes overrides and importing instructions.
For more information view the navigation and sub-navigation design spec, which includes the specification in markdown format and a PNG image.