React Navs & Tabs Components

Documentation and examples for how to use CoreUI's included React navigation components.

Base nav#

Navigation available in CoreUI for React share general markup and styles, from the base .nav class to the active and disabled states. Swap modifier classes to switch between each style.

The base <CNav> component is built with flexbox and provide a strong foundation for building all types of navigation components. It includes some style overrides (for working with lists), some link padding for larger hit areas, and basic disabled styling.

1<CNav>
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

Classes are used throughout, so your markup can be super flexible. Use <ul>s like above, <ol> if the order of your items is important, or roll your own with a <nav> element. Because the .nav uses display: flex, the nav links behave the same as nav items would, but without the extra markup.

1<CNav component="nav">
2 <CNavLink href="#" active>
3 Active
4 </CNavLink>
5 <CNavLink href="#">Link</CNavLink>
6 <CNavLink href="#">Link</CNavLink>
7 <CNavLink href="#" disabled>
8 Disabled
9 </CNavLink>
10</CNav>

Available styles#

Change the style of <CNav>'s component with modifiers and utilities. Mix and match as needed, or build your own.

Horizontal alignment#

Change the horizontal alignment of your nav with flexbox utilities. By default, navs are left-aligned, but you can easily change them to center or right aligned.

Centered with .justify-content-center:

1<CNav className="justify-content-center">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

Right-aligned with .justify-content-end:

1<CNav className="justify-content-end">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

Vertical#

Stack your navigation by changing the flex item direction with the .flex-column utility. Need to stack them on some viewports but not others? Use the responsive versions (e.g., .flex-sm-column).

1<CNav className="flex-column">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

Tabs#

Takes the basic nav from above and adds the variant="tabs" class to generate a tabbed interface

1<CNav variant="tabs">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

Pills#

Take that same HTML, but use variant="pills" instead:

1<CNav variant="pills">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

Underline#

Take that same HTML, but use variant="underline" instead:

1<CNav variant="underline">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

Fill and justify#

Force your <CNav>'s contents to extend the full available width one of two modifier classes. To proportionately fill all available space with your .nav-items, use layout="fill". Notice that all horizontal space is occupied, but not every nav item has the same width.

1<CNav variant="pills" layout="fill">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

For equal-width elements, use layout="justified". All horizontal space will be occupied by nav links, but unlike the .nav-fill above, every nav item will be the same width.

1<CNav variant="pills" layout="justified">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CNavItem>
8 <CNavLink href="#">Link</CNavLink>
9 </CNavItem>
10 <CNavItem>
11 <CNavLink href="#">Link</CNavLink>
12 </CNavItem>
13 <CNavItem>
14 <CNavLink href="#" disabled>
15 Disabled
16 </CNavLink>
17 </CNavItem>
18</CNav>

Working with flex utilities#

If you need responsive nav variations, consider using a series of flexbox utilities. While more verbose, these utilities offer greater customization across responsive breakpoints. In the example below, our nav will be stacked on the lowest breakpoint, then adapt to a horizontal layout that fills the available width starting from the small breakpoint.

1<CNav component="nav" variant="pills" className="flex-column flex-sm-row">
2 <CNavLink href="#" active>
3 Active
4 </CNavLink>
5 <CNavLink href="#">Link</CNavLink>
6 <CNavLink href="#">Link</CNavLink>
7 <CNavLink href="#" disabled>
8 Disabled
9 </CNavLink>
10</CNav>

Regarding accessibility#

If you're using navs to provide a navigation bar, be sure to add a role="navigation" to the most logical parent container of the <ul>, or wrap a <nav> element around the whole navigation. Do not add the role to the <ul> itself, as this would prevent it from being announced as an actual list by assistive technologies.

Note that navigation bars, even if visually styled as tabs with the .nav-tabs class, should not be given role="tablist", role="tab" or role="tabpanel" attributes. These are only appropriate for dynamic tabbed interfaces, as described in the WAI ARIA Authoring Practices. See JavaScript behavior for dynamic tabbed interfaces in this section for an example. The aria-current attribute is not necessary on dynamic tabbed interfaces since our JavaScript handles the selected state by adding aria-selected="true" on the active tab.

Using dropdowns#

Add dropdown menus with a little extra HTML.

Tabs with dropdowns#

1<CNav>
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CDropdown variant="nav-item">
8 <CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
9 <CDropdownMenu>
10 <CDropdownItem href="#">Action</CDropdownItem>
11 <CDropdownItem href="#">Another action</CDropdownItem>
12 <CDropdownItem href="#">Something else here</CDropdownItem>
13 </CDropdownMenu>
14 </CDropdown>
15 <CNavItem>
16 <CNavLink href="#">Link</CNavLink>
17 </CNavItem>
18 <CNavItem>
19 <CNavLink href="#" disabled>
20 Disabled
21 </CNavLink>
22 </CNavItem>
23</CNav>

Pills with dropdowns#

1<CNav variant="pills">
2 <CNavItem>
3 <CNavLink href="#" active>
4 Active
5 </CNavLink>
6 </CNavItem>
7 <CDropdown variant="nav-item">
8 <CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
9 <CDropdownMenu>
10 <CDropdownItem href="#">Action</CDropdownItem>
11 <CDropdownItem href="#">Another action</CDropdownItem>
12 <CDropdownItem href="#">Something else here</CDropdownItem>
13 </CDropdownMenu>
14 </CDropdown>
15 <CNavItem>
16 <CNavLink href="#">Link</CNavLink>
17 </CNavItem>
18 <CNavItem>
19 <CNavLink href="#" disabled>
20 Disabled
21 </CNavLink>
22 </CNavItem>
23</CNav>

Tab panes#

Dynamic tabbed interfaces, as described in the WAI ARIA Authoring Practices, require role="tablist", role="tab", role="tabpanel", and additional aria- attributes in order to convey their structure, functionality and current state to users of assistive technologies (such as screen readers).

Note that dynamic tabbed interfaces should not contain dropdown menus, as this causes both usability and accessibility issues. From a usability perspective, the fact that the currently displayed tab's trigger element is not immediately visible (as it's inside the closed dropdown menu) can cause confusion. From an accessibility point of view, there is currently no sensible way to map this sort of construct to a standard WAI ARIA pattern, meaning that it cannot be easily made understandable to users of assistive technologies.

Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.
Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.
1const [activeKey, setActiveKey] = useState(1)
2return (
3 <>
4 <CNav variant="tabs" role="tablist">
5 <CNavItem>
6 <CNavLink
7 href="javascript:void(0);"
8 active={activeKey === 1}
9 onClick={() => setActiveKey(1)}
10 >
11 Home
12 </CNavLink>
13 </CNavItem>
14 <CNavItem>
15 <CNavLink
16 href="javascript:void(0);"
17 active={activeKey === 2}
18 onClick={() => setActiveKey(2)}
19 >
20 Profile
21 </CNavLink>
22 </CNavItem>
23 <CNavItem>
24 <CNavLink
25 href="javascript:void(0);"
26 active={activeKey === 3}
27 onClick={() => setActiveKey(3)}
28 >
29 Contact
30 </CNavLink>
31 </CNavItem>
32 </CNav>
33 <CTabContent>
34 <CTabPane role="tabpanel" aria-labelledby="home-tab" visible={activeKey === 1}>
35 Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown
36 aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan
37 helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh
38 mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan
39 aliquip quis cardigan american apparel, butcher voluptate nisi qui.
40 </CTabPane>
41 <CTabPane role="tabpanel" aria-labelledby="profile-tab" visible={activeKey === 2}>
42 Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid.
43 Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan
44 four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft
45 beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda
46 labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit
47 sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean
48 shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown,
49 tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
50 </CTabPane>
51 <CTabPane role="tabpanel" aria-labelledby="contact-tab" visible={activeKey === 3}>
52 Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic
53 lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork
54 tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica.
55 DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh
56 mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog.
57 Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown.
58 Pitchfork sustainable tofu synth chambray yr.
59 </CTabPane>
60 </CTabContent>
61 </>
62)

The tabs also works with pills.

Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.
Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.
1const [activeKey, setActiveKey] = useState(1)
2return (
3 <>
4 <CNav variant="pills" role="tablist">
5 <CNavItem>
6 <CNavLink
7 href="javascript:void(0);"
8 active={activeKey === 1}
9 onClick={() => setActiveKey(1)}
10 >
11 Home
12 </CNavLink>
13 </CNavItem>
14 <CNavItem>
15 <CNavLink
16 href="javascript:void(0);"
17 active={activeKey === 2}
18 onClick={() => setActiveKey(2)}
19 >
20 Profile
21 </CNavLink>
22 </CNavItem>
23 <CNavItem>
24 <CNavLink
25 href="javascript:void(0);"
26 active={activeKey === 3}
27 onClick={() => setActiveKey(3)}
28 >
29 Contact
30 </CNavLink>
31 </CNavItem>
32 </CNav>
33 <CTabContent>
34 <CTabPane role="tabpanel" aria-labelledby="home-tab" visible={activeKey === 1}>
35 Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown
36 aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan
37 helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh
38 mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan
39 aliquip quis cardigan american apparel, butcher voluptate nisi qui.
40 </CTabPane>
41 <CTabPane role="tabpanel" aria-labelledby="profile-tab" visible={activeKey === 2}>
42 Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid.
43 Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan
44 four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft
45 beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda
46 labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit
47 sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean
48 shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown,
49 tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
50 </CTabPane>
51 <CTabPane role="tabpanel" aria-labelledby="contact-tab" visible={activeKey === 3}>
52 Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic
53 lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork
54 tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica.
55 DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh
56 mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog.
57 Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown.
58 Pitchfork sustainable tofu synth chambray yr.
59 </CTabPane>
60 </CTabContent>
61 </>
62)

API#

CNav#

1import { CNav } from '@coreui/react'
2// or
3import CNav from '@coreui/react/src/components/nav/CNav'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the base component.string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>-
layoutSpecify a layout type for component.'fill' | 'justified'-
variantSet the nav variant to tabs or pills.'tabs' | 'pills' | 'underline'-

CNavItem#

1import { CNavItem } from '@coreui/react'
2// or
3import CNavItem from '@coreui/react/src/components/nav/CNavItem'
PropertyDescriptionTypeDefault
activeToggle the active state for the component.boolean-
classNameA string of all className you want applied to the component.string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>-
disabledToggle the disabled state for the component.boolean-
hrefThe href attribute specifies the URL of the page the link goes to.string-
1import { CNavLink } from '@coreui/react'
2// or
3import CNavLink from '@coreui/react/src/components/nav/CNavLink'
PropertyDescriptionTypeDefault
activeToggle the active state for the component.boolean-
classNameA string of all className you want applied to the component.string-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>-
disabledToggle the disabled state for the component.boolean-
hrefThe href attribute specifies the URL of the page the link goes to.string-

CTabContent#

1import { CTabContent } from '@coreui/react'
2// or
3import CTabContent from '@coreui/react/src/components/tabs/CTabContent'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the base component.string-

CTabPane#

1import { CTabPane } from '@coreui/react'
2// or
3import CTabPane from '@coreui/react/src/components/tabs/CTabPane'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the base component.string-
onHideCallback fired when the component requests to be hidden.() => void-
onShowCallback fired when the component requests to be shown.() => void-
visibleToggle the visibility of component.boolean-