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.
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 change the breakpoint at which the menu changes to a small screen menu
by adjusting the
$breakpoint-navigation-threshold variable from
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.
Expanding search box
Expanding search in main navigation consists of couple of elements: two search toggle links (
.p-navigation__link--search-toggle) - one inside
.p-navigation__banner for mobile view and another in
.p-navigation__nav as one of standard view items, the expanding search box (
.p-navigation__search) and an overlay that covers whole screen when search is expanded (
.p-navigation__link--search-toggle class name is used to add a search toggle link to navigation items. The label text of this toggle element should be wrapped in
.p-navigation__search-label element to make sure it's hidden on smaller screen sizes. Click event handler attached to the toggle element should add
.has-search-open class on main
.p-navigation element to expand the search box and show the overlay.
Vanilla Search box component is used for the search field, but it's wrapped into an element with
.p-navigation__search class name. The search will be hidden by default and only expands when the navigation element has
.has-search-open class name.
When search box is expanded the overlay element (
p-navigation__search-overlay) is faded in to cover all the contents of the page (except the search box itself). Clicking anywhere on the overlay (or hitting Escape key) closes the search box.
On small screens the search box and menu items can be expanded individually as their own separate dropdowns.
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
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
To add accordions within side navigation use the
.p-side-navigation--accordion class on the root element of the side navigation and
.p-side-navigation__accordion-button to accordion
button elements. The accordion will be collapsed by default and can be expanded by clicking on the accordion button.
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.
Side navigation in default variant.
Side navigation with item icons.
Side navigation with expanding accordion items.
Raw HTML version of side navigation (used with links generated by an external service).
.is-drawer-expanded when side navigation drawer is open on small screens.
.is-drawer-collapsed when side navigation drawer is closed on small screens.
.is-drawer-hidden when side navigation drawer is closed on small screens.
Sticky version of side navigation.
Side navigation in dark theme (if default is light).
Side navigation in light theme (if default is dark).
Screen overlay to display when side navigation drawer is open on small screens.
Side navigation drawer (to allow expanding and collapsing the navigation on small screens).
Header of the side navigation drawer.
Side navigation toggle button (to open side navigation on small screens).
Side navigation toggle button in drawer (to close navigation on small screens).
Items list heading
Heading for side navigation items group (text only).
Heading for side navigation items group that contains a link (
Group of side navigation items (usually a
Single item in side navigation (usually a
<li> element). May contain nested items lists.
Single title item in side navigation (usually a
.has-active-child on a item that contains an active nested item. This is used in collapsible side navigation in application layout.
Single link in the side navigation.
Single text item in side navigation (for items that are not linked).
Item accordion button
Single accordion button item in side navigation with
An icon in side navigation item (used with
A container for status icon or label inside the navigation item.
On small screens side navigation is rendered off-screen as a drawer. To open the side navigation drawer, add
is-drawer-expanded class to
.p-side-navigation element. To close the drawer (with the animation) remove
is-drawer-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 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'; @include vf-base; @include vf-p-navigation;
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'; @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-status-label; @include vf-p-icons;
For more information see Customising Vanilla in your projects, which includes overrides and importing instructions.