Skip to main content
U.S. Flag

An official website of the United States government

CMS Design System

Vertical navigation

Jump to Guidance
View related guidance in the U.S. Web Design System

Hierarchical, vertical navigation.

<VerticalNav>

A VerticalNav component accepts list items as a JSON object and includes additional functionality like collapsible nested menus.

View Source File

Code snippet

Vertical Nav Props

React Properties Documentation
NameTypeDefaultDescription
ariaNavLabelstring

An optional arial label for the <nav> element in this component. This prop is necessary when there is more than one nav element on a page.

classNamestring

Additional classes to be added to the root element

collapsedbooleanfalse

Whether or not the menu is in a collapsed state

componentReact.ReactElement<any> | any | ((...args: any[]) => any)

When provided, this will render the passed in component for all VerticalNavItems. This is useful when integrating with React Router's <Link> or using your own custom component. If more specific control is needed, each VerticalNavItem object also accepts a component prop.

selectedIdstring

The id of the selected VerticalNavItem. This will also set the selected prop on the item's parents.

idstring
itemsrequiredVerticalNavItemProps[]

An array of VerticalNavItem data objects

nestedboolean

Indicates this list is nested within another nav item.

onLinkClick(evt: React.MouseEvent | React.KeyboardEvent, id: string, url: string) => any

Called when one of the nav links is clicked, with the following arguments: SyntheticEvent, id, url

<VerticalNavItem>

View Source File

Vertical Nav Item Props

React Properties Documentation
NameTypeDefaultDescription
ariaCollapsedStateButtonLabelstring'Expand sub-navigation'

Aria label for the toggle button when the sub-navigation is collapsed

ariaExpandedStateButtonLabelstring'Collapse sub-navigation'

Aria label for the toggle button when the sub-navigation is expanded

classNamestring

Additional classes to be added to the root element

componentReact.ReactElement<any> | any | ((...args: any[]) => any)

When provided, this will render the passed in component. This is useful when integrating with React Router's <Link> or using your own custom component.

defaultCollapsedbooleanfalse

Whether or not the item's sub-navigation is in a collapsed state by default

onClick(evt: React.MouseEvent | React.KeyboardEvent, id: string, url: string) => any

Called when the link is clicked, with the following arguments: SyntheticEvent, id, url. This takes precedence over the VerticalNav onLinkClick prop

onSubnavToggle(id: string, collapsed: boolean) => any

Called when this item's subnav is collapsed or expanded, with the following arguments: id, collapsed

idstring

Optional identifier. This can be handy if you're passing in an onClick handler. A unique ID will be generated if one isn't provided.

itemsany[]

An array of nested VerticalNavItem data objects to be rendered in a sub-navigation list.

labelrequiredReact.ReactNode

Text to render for this nav item

urlstring

A URL to navigate to if this item is a link

selectedboolean

If this item is currently selected

Guidance

When to use

  • To display a navigational hierarchy with one to three levels.
  • To display the “sub-navigation” within a section of the website.

When to consider alternatives

  • If the site has fewer than five pages, consider organizing the page without a navigational hierarchy.
  • If your page already has a horizontal and vertical navigation bar, consider ways to simplify your navigation system.
  • If your content is within a frame or sub-area of a page, consider ways to simplify your navigation system.

Usage

  • Indicate where a user is within the navigational hierarchy. Use the .ds-c-vertical-nav__label--current modifier to show users which page they have navigated to.
  • Keep the navigation links short and follow sentence case. They can be shorter derivatives of page titles themselves.
  • If the navigation hierarchy is too long, users may miss items at the bottom. If it’s too deep, users may miss items that require too many clicks. Usability test to find the right balance between breadth and depth.

Accessibility

  • Users should be able to tab through each link.
  • If you have nested menus that are collapsible, ensure the toggle button has its aria-controls and aria-expanded attributes set. This is done automatically for you if you're using the React components.
  • If your navigation list is longer than 3 items, consider using a skip navigation link. This allows screen reader and keyboard users to skip to the main content area(s).
  • If a skip navigation link is not an option, consider using:
    • A valid, descriptive page header
    • Landmark regions like <header>, <main>, <aside>, <footer>
  • When naming the optional ariaNavLabel prop, keep in mind:
    • This prop is necessary only when there is more than one nav element on a page.
    • Don't include the word "Menu" in the label. Most screen readers will announce that information already. Instead, provide more context to what's in the menu and/or its location. Like "Main" or "Social".

Customization

The following Sass variables can be overridden to customize VerticalNav components:

VariableDefault Core Theme Value
$vertical-nav-item__background-color--hover$color-gray-lightest
$vertical-nav-item__color--hover$color-primary
$vertical-nav-item__border-color$color-gray
$vertical-nav-label__color$color-base
$vertical-nav-label-icon__color$color-base
$vertical-nav-label__border-color--current$color-primary
$vertical-nav-label__color--current$color-primary

Learn more