React Navbar Component

Documentation and examples for the React navbar powerful, responsive navigation header component. Includes support for branding, links, dropdowns, and more.

Supported content#

<CNavbar> come with built-in support for a handful of sub-components. Choose from the following as needed:

  • <CNavbarBrand> for your company, product, or project name.
  • <CNavbarNav> for a full-height and lightweight navigation (including support for dropdowns).
  • <CNavbarToggler> for use with our collapse plugin and other navigation toggling behaviors.
  • Flex and spacing utilities for any form controls and actions.
  • <CNavbarText> for adding vertically centered strings of text.
  • <CCollapse> for grouping and hiding navbar contents by a parent breakpoint.

Here's an example of all the sub-components included in a responsive light-themed navbar that automatically collapses at the lg (large) breakpoint.

Basic usage#

1const [visible, setVisible] = useState(false)
2return (
3 <>
4 <CNavbar expand="lg" colorScheme="light" className="bg-light">
5 <CContainer fluid>
6 <CNavbarBrand href="#">Navbar</CNavbarBrand>
7 <CNavbarToggler onClick={() => setVisible(!visible)} />
8 <CCollapse className="navbar-collapse" visible={visible}>
9 <CNavbarNav>
10 <CNavItem>
11 <CNavLink href="#" active>
12 Home
13 </CNavLink>
14 </CNavItem>
15 <CNavItem>
16 <CNavLink href="#">Link</CNavLink>
17 </CNavItem>
18 <CDropdown variant="nav-item" popper={false}>
19 <CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
20 <CDropdownMenu>
21 <CDropdownItem href="#">Action</CDropdownItem>
22 <CDropdownItem href="#">Another action</CDropdownItem>
23 <CDropdownDivider />
24 <CDropdownItem href="#">Something else here</CDropdownItem>
25 </CDropdownMenu>
26 </CDropdown>
27 <CNavItem>
28 <CNavLink href="#" disabled>
29 Disabled
30 </CNavLink>
31 </CNavItem>
32 </CNavbarNav>
33 <CForm className="d-flex">
34 <CFormInput type="search" className="me-2" placeholder="Search" />
35 <CButton type="submit" color="success" variant="outline">
36 Search
37 </CButton>
38 </CForm>
39 </CCollapse>
40 </CContainer>
41 </CNavbar>
42 </>
43)

Brand#

The <CNavbarBrand> can be applied to most elements, but an anchor works best, as some elements might require utility classes or custom styles.


1{/* As a link */}
2<CNavbar colorScheme="light" className="bg-light">
3 <CContainer fluid>
4 <CNavbarBrand href="#">Navbar</CNavbarBrand>
5 </CContainer>
6</CNavbar>
7<br/>
8{/* As a heading */}
9<CNavbar colorScheme="light" className="bg-light">
10 <CContainer fluid>
11 <CNavbarBrand className="mb-0 h1">Navbar</CNavbarBrand>
12 </CContainer>
13</CNavbar>

Adding images to the <CNavbarBrand> will likely always require custom styles or utilities to properly size. Here are some examples to demonstrate.

1{ /* Just an image */ }
2<CNavbar colorScheme="light" className="bg-light">
3 <CContainer fluid>
4 <CNavbarBrand href="#">
5 <img src="/images/brand/coreui-signet.svg" alt="" width="22" height="24" />
6 </CNavbarBrand>
7 </CContainer>
8</CNavbar>
1{/* Image and text */}
2<CNavbar colorScheme="light" className="bg-light">
3 <CContainer fluid>
4 <CNavbarBrand href="#">
5 <img
6 src="/images/brand/coreui-signet.svg"
7 alt=""
8 width="22"
9 height="24"
10 className="d-inline-block align-top"
11 />{' '}
12 CoreUI
13 </CNavbarBrand>
14 </CContainer>
15</CNavbar>

<CNavbar> navigation is based on <CNavbarNav>. Navigation in navbars will also grow to occupy as much horizontal space as possible to keep your navbar contents securely aligned.

1const [visible, setVisible] = useState(false)
2return (
3 <>
4 <CNavbar expand="lg" colorScheme="light" className="bg-light">
5 <CContainer fluid>
6 <CNavbarBrand href="#">Navbar</CNavbarBrand>
7 <CNavbarToggler
8 aria-label="Toggle navigation"
9 aria-expanded={visible}
10 onClick={() => setVisible(!visible)}
11 />
12 <CCollapse className="navbar-collapse" visible={visible}>
13 <CNavbarNav>
14 <CNavItem>
15 <CNavLink href="#" active>
16 Home
17 </CNavLink>
18 </CNavItem>
19 <CNavItem>
20 <CNavLink href="#">Features</CNavLink>
21 </CNavItem>
22 <CNavItem>
23 <CNavLink href="#">Pricing</CNavLink>
24 </CNavItem>
25 <CNavItem>
26 <CNavLink href="#" disabled>
27 Disabled
28 </CNavLink>
29 </CNavItem>
30 </CNavbarNav>
31 </CCollapse>
32 </CContainer>
33 </CNavbar>
34 </>
35)

And because we use classes for our navs, you can avoid the list-based approach entirely if you like.

1const [visible, setVisible] = useState(false)
2return (
3 <>
4 <CNavbar expand="lg" colorScheme="light" className="bg-light">
5 <CContainer fluid>
6 <CNavbarBrand href="#">Navbar</CNavbarBrand>
7 <CNavbarToggler
8 aria-label="Toggle navigation"
9 aria-expanded={visible}
10 onClick={() => setVisible(!visible)}
11 />
12 <CCollapse className="navbar-collapse" visible={visible}>
13 <CNavbarNav component="nav">
14 <CNavLink href="#" active>
15 Home
16 </CNavLink>
17 <CNavLink href="#">Features</CNavLink>
18 <CNavLink href="#">Pricing</CNavLink>
19 <CNavLink href="#" disabled>
20 Disabled
21 </CNavLink>
22 </CNavbarNav>
23 </CCollapse>
24 </CContainer>
25 </CNavbar>
26 </>
27)

You can also use dropdowns in your navbar. Please note that <CDropdown> component requires variant="nav-item".

1const [visible, setVisible] = useState(false)
2return (
3 <>
4 <CNavbar expand="lg" colorScheme="light" className="bg-light">
5 <CContainer fluid>
6 <CNavbarBrand href="#">Navbar</CNavbarBrand>
7 <CNavbarToggler
8 aria-label="Toggle navigation"
9 aria-expanded={visible}
10 onClick={() => setVisible(!visible)}
11 />
12 <CCollapse className="navbar-collapse" visible={visible}>
13 <CNavbarNav>
14 <CNavItem>
15 <CNavLink href="#" active>
16 Home
17 </CNavLink>
18 </CNavItem>
19 <CNavItem>
20 <CNavLink href="#">Features</CNavLink>
21 </CNavItem>
22 <CNavItem>
23 <CNavLink href="#">Pricing</CNavLink>
24 </CNavItem>
25 <CDropdown variant="nav-item" popper={false}>
26 <CDropdownToggle>Dropdown link</CDropdownToggle>
27 <CDropdownMenu>
28 <CDropdownItem href="#">Action</CDropdownItem>
29 <CDropdownItem href="#">Another action</CDropdownItem>
30 <CDropdownDivider />
31 <CDropdownItem href="#">Something else here</CDropdownItem>
32 </CDropdownMenu>
33 </CDropdown>
34 </CNavbarNav>
35 </CCollapse>
36 </CContainer>
37 </CNavbar>
38 </>
39)

Forms#

Place various form controls and components within a navbar:

1<CNavbar colorScheme="light" className="bg-light">
2 <CContainer fluid>
3 <CForm className="d-flex">
4 <CFormInput type="search" className="me-2" placeholder="Search" />
5 <CButton type="submit" color="success" variant="outline">
6 Search
7 </CButton>
8 </CForm>
9 </CContainer>
10</CNavbar>

Immediate child elements of <CNavbar> use flex layout and will default to justify-content: space-between. Use additional flex utilities as needed to adjust this behavior.

1<CNavbar colorScheme="light" className="bg-light">
2 <CContainer fluid>
3 <CNavbarBrand href="#">Navbar</CNavbarBrand>
4 <CForm className="d-flex">
5 <CFormInput type="search" className="me-2" placeholder="Search" />
6 <CButton type="submit" color="success" variant="outline">
7 Search
8 </CButton>
9 </CForm>
10 </CContainer>
11</CNavbar>

Input groups work, too. If your navbar is an entire form, or mostly a form, you can use the <CForm> element as the container and save some HTML.

1<CNavbar colorScheme="light" className="bg-light">
2 <CForm className="container-fluid">
3 <CInputGroup>
4 <CInputGroupText id="basic-addon1">@</CInputGroupText>
5 <CFormInput placeholder="Username" aria-label="Username" aria-describedby="basic-addon1" />
6 </CInputGroup>
7 </CForm>
8</CNavbar>

Various buttons are supported as part of these navbar forms, too. This is also a great reminder that vertical alignment utilities can be used to align different sized elements.

1<CNavbar colorScheme="light" className="bg-light">
2 <CForm className="container-fluid justify-content-start">
3 <CButton type="button" color="success" variant="outline" className="me-2">
4 Main button
5 </CButton>
6 <CButton type="button" color="secondary" variant="outline" size="sm">
7 Smaller button
8 </CButton>
9 </CForm>
10</CNavbar>

Text#

Navbars may contain bits of text with the help of <CNavbarText>. This class adjusts vertical alignment and horizontal spacing for strings of text.

1<CNavbar colorScheme="light" className="bg-light">
2 <CContainer fluid>
3 <CNavbarText>Navbar text with an inline element</CNavbarText>
4 </CContainer>
5</CNavbar>

Color schemes#

Theming the navbar has never been easier thanks to the combination of theming classes and background-color utilities. Set colorScheme="light" for use with light background colors, or colorScheme="dark" for dark background colors. Then, customize with .bg-* utilities.

1const [visible, setVisible] = useState(false)
2return (
3 <>
4 <CNavbar expand="lg" colorScheme="dark" className="bg-dark">
5 <CContainer fluid>
6 <CNavbarBrand href="#">Navbar</CNavbarBrand>
7 <CNavbarToggler
8 aria-label="Toggle navigation"
9 aria-expanded={visible}
10 onClick={() => setVisible(!visible)}
11 />
12 <CCollapse className="navbar-collapse" visible={visible}>
13 <CNavbarNav>
14 <CNavItem>
15 <CNavLink href="#" active>
16 Home
17 </CNavLink>
18 </CNavItem>
19 <CNavItem>
20 <CNavLink href="#">Link</CNavLink>
21 </CNavItem>
22 <CDropdown variant="nav-item" popper={false}>
23 <CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
24 <CDropdownMenu>
25 <CDropdownItem href="#">Action</CDropdownItem>
26 <CDropdownItem href="#">Another action</CDropdownItem>
27 <CDropdownDivider />
28 <CDropdownItem href="#">Something else here</CDropdownItem>
29 </CDropdownMenu>
30 </CDropdown>
31 <CNavItem>
32 <CNavLink href="#" disabled>
33 Disabled
34 </CNavLink>
35 </CNavItem>
36 </CNavbarNav>
37 <CForm className="d-flex">
38 <CFormInput type="search" className="me-2" placeholder="Search" />
39 <CButton type="submit" color="light" variant="outline">
40 Search
41 </CButton>
42 </CForm>
43 </CCollapse>
44 </CContainer>
45 </CNavbar>
46 <br />
47 <CNavbar expand="lg" colorScheme="dark" className="bg-primary">
48 <CContainer fluid>
49 <CNavbarBrand href="#">Navbar</CNavbarBrand>
50 <CNavbarToggler
51 aria-label="Toggle navigation"
52 aria-expanded={visible}
53 onClick={() => setVisible(!visible)}
54 />
55 <CCollapse className="navbar-collapse" visible={visible}>
56 <CNavbarNav>
57 <CNavItem>
58 <CNavLink href="#" active>
59 Home
60 </CNavLink>
61 </CNavItem>
62 <CNavItem>
63 <CNavLink href="#">Link</CNavLink>
64 </CNavItem>
65 <CDropdown variant="nav-item" popper={false}>
66 <CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
67 <CDropdownMenu>
68 <CDropdownItem href="#">Action</CDropdownItem>
69 <CDropdownItem href="#">Another action</CDropdownItem>
70 <CDropdownDivider />
71 <CDropdownItem href="#">Something else here</CDropdownItem>
72 </CDropdownMenu>
73 </CDropdown>
74 <CNavItem>
75 <CNavLink href="#" disabled>
76 Disabled
77 </CNavLink>
78 </CNavItem>
79 </CNavbarNav>
80 <CForm className="d-flex">
81 <CFormInput type="search" className="me-2" placeholder="Search" />
82 <CButton type="submit" color="light" variant="outline">
83 Search
84 </CButton>
85 </CForm>
86 </CCollapse>
87 </CContainer>
88 </CNavbar>
89 <br />
90 <CNavbar expand="lg" colorScheme="light" style={{ backgroundColor: '#e3f2fd' }}>
91 <CContainer fluid>
92 <CNavbarBrand href="#">Navbar</CNavbarBrand>
93 <CNavbarToggler
94 aria-label="Toggle navigation"
95 aria-expanded={visible}
96 onClick={() => setVisible(!visible)}
97 />
98 <CCollapse className="navbar-collapse" visible={visible}>
99 <CNavbarNav>
100 <CNavItem>
101 <CNavLink href="#" active>
102 Home
103 </CNavLink>
104 </CNavItem>
105 <CNavItem>
106 <CNavLink href="#">Link</CNavLink>
107 </CNavItem>
108 <CDropdown variant="nav-item" popper={false}>
109 <CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
110 <CDropdownMenu>
111 <CDropdownItem href="#">Action</CDropdownItem>
112 <CDropdownItem href="#">Another action</CDropdownItem>
113 <CDropdownDivider />
114 <CDropdownItem href="#">Something else here</CDropdownItem>
115 </CDropdownMenu>
116 </CDropdown>
117 <CNavItem>
118 <CNavLink href="#" disabled>
119 Disabled
120 </CNavLink>
121 </CNavItem>
122 </CNavbarNav>
123 <CForm className="d-flex">
124 <CFormInput type="search" className="me-2" placeholder="Search" />
125 <CButton type="submit" color="primary" variant="outline">
126 Search
127 </CButton>
128 </CForm>
129 </CCollapse>
130 </CContainer>
131 </CNavbar>
132 </>
133)

Containers#

Although it's not required, you can wrap a <CNavbar> in a <CContainer> to center it on a page–though note that an inner container is still required. Or you can add a container inside the <CNavbar> to only center the contents of a fixed or static top navbar.

1<CContainer>
2 <CNavbar colorScheme="light" className="bg-light">
3 <CContainer fluid>
4 <CNavbarBrand href="#">Navbar</CNavbarBrand>
5 </CContainer>
6 </CNavbar>
7</CContainer>

Use any of the responsive containers to change how wide the content in your navbar is presented.

1<CNavbar colorScheme="light" className="bg-light">
2 <CContainer breakpoint="md">
3 <CNavbarBrand href="#">Navbar</CNavbarBrand>
4 </CContainer>
5</CNavbar>

Placement#

Use our placement properly to place navbars in non-static positions. Choose from fixed to the top, fixed to the bottom, or stickied to the top (scrolls with the page until it reaches the top, then stays there). Fixed navbars use position: fixed, meaning they're pulled from the normal flow of the DOM and may require custom CSS (e.g., padding-top on the <body>) to prevent overlap with other elements.

Also note that .sticky-top uses position: sticky, which isn't fully supported in every browser.

1<CNavbar colorScheme="light" className="bg-light">
2 <CContainer fluid>
3 <CNavbarBrand href="#">Default</CNavbarBrand>
4 </CContainer>
5</CNavbar>
1<CNavbar colorScheme="light" className="bg-light" placement="fixed-top">
2 <CContainer fluid>
3 <CNavbarBrand href="#">Fixed top</CNavbarBrand>
4 </CContainer>
5</CNavbar>
1<CNavbar colorScheme="light" className="bg-light" placement="fixed-bottom">
2 <CContainer fluid>
3 <CNavbarBrand href="#">Fixed bottom</CNavbarBrand>
4 </CContainer>
5</CNavbar>
1<CNavbar colorScheme="light" className="bg-light" placement="sticky-top">
2 <CContainer fluid>
3 <CNavbarBrand href="#">Sticky top</CNavbarBrand>
4 </CContainer>
5</CNavbar>

Responsive behaviors#

Navbars can use <CNavbarToggler>, <CCollapse>, and expand="{sm|md|lg|xl|xxl}" property to determine when their content collapses behind a button. In combination with other utilities, you can easily choose when to show or hide particular elements.

For navbars that never collapse, add the expand boolean property on the <CNavbar>. For navbars that always collapse, don't add any property.

Toggler#

Navbar togglers are left-aligned by default, but should they follow a sibling element like a <CNavbarBrand>, they'll automatically be aligned to the far right. Reversing your markup will reverse the placement of the toggler. Below are examples of different toggle styles.

With no <CNavbarBrand> shown at the smallest breakpoint:

1const [visible, setVisible] = useState(false)
2return (
3 <>
4 <CNavbar expand="lg" colorScheme="light" className="bg-light">
5 <CContainer fluid>
6 <CNavbarToggler
7 aria-label="Toggle navigation"
8 aria-expanded={visible}
9 onClick={() => setVisible(!visible)}
10 />
11 <CCollapse className="navbar-collapse" visible={visible}>
12 <CNavbarBrand href="#">Hidden brand</CNavbarBrand>
13 <CNavbarNav className="me-auto mb-2 mb-lg-0">
14 <CNavItem>
15 <CNavLink href="#" active>
16 Home
17 </CNavLink>
18 </CNavItem>
19 <CNavItem>
20 <CNavLink href="#">Link</CNavLink>
21 </CNavItem>
22 <CNavItem>
23 <CNavLink href="#" disabled>
24 Disabled
25 </CNavLink>
26 </CNavItem>
27 </CNavbarNav>
28 <CForm className="d-flex">
29 <CFormInput type="search" className="me-2" placeholder="Search" />
30 <CButton type="submit" color="success" variant="outline">
31 Search
32 </CButton>
33 </CForm>
34 </CCollapse>
35 </CContainer>
36 </CNavbar>
37 </>
38)

With a brand name shown on the left and toggler on the right:

1const [visible, setVisible] = useState(false)
2return (
3 <>
4 <CNavbar expand="lg" colorScheme="light" className="bg-light">
5 <CContainer fluid>
6 <CNavbarBrand href="#">Navbar</CNavbarBrand>
7 <CNavbarToggler
8 aria-label="Toggle navigation"
9 aria-expanded={visible}
10 onClick={() => setVisible(!visible)}
11 />
12 <CCollapse className="navbar-collapse" visible={visible}>
13 <CNavbarNav className="me-auto mb-2 mb-lg-0">
14 <CNavItem>
15 <CNavLink href="#" active>
16 Home
17 </CNavLink>
18 </CNavItem>
19 <CNavItem>
20 <CNavLink href="#">Link</CNavLink>
21 </CNavItem>
22 <CNavItem>
23 <CNavLink href="#" disabled>
24 Disabled
25 </CNavLink>
26 </CNavItem>
27 </CNavbarNav>
28 <CForm className="d-flex">
29 <CFormInput type="search" className="me-2" placeholder="Search" />
30 <CButton type="submit" color="success" variant="outline">
31 Search
32 </CButton>
33 </CForm>
34 </CCollapse>
35 </CContainer>
36 </CNavbar>
37 </>
38)

With a toggler on the left and brand name on the right:

1const [visible, setVisible] = useState(false)
2return (
3 <>
4 <CNavbar expand="lg" colorScheme="light" className="bg-light">
5 <CContainer fluid>
6 <CNavbarToggler
7 aria-label="Toggle navigation"
8 aria-expanded={visible}
9 onClick={() => setVisible(!visible)}
10 />
11 <CNavbarBrand href="#">Navbar</CNavbarBrand>
12 <CCollapse className="navbar-collapse" visible={visible}>
13 <CNavbarNav className="me-auto mb-2 mb-lg-0">
14 <CNavItem>
15 <CNavLink href="#" active>
16 Home
17 </CNavLink>
18 </CNavItem>
19 <CNavItem>
20 <CNavLink href="#">Link</CNavLink>
21 </CNavItem>
22 <CNavItem>
23 <CNavLink href="#" disabled>
24 Disabled
25 </CNavLink>
26 </CNavItem>
27 </CNavbarNav>
28 <CForm className="d-flex">
29 <CFormInput type="search" className="me-2" placeholder="Search" />
30 <CButton type="submit" color="success" variant="outline">
31 Search
32 </CButton>
33 </CForm>
34 </CCollapse>
35 </CContainer>
36 </CNavbar>
37 </>
38)

API#

CNavbar#

1import { CNavbar } from '@coreui/react'
2// or
3import CNavbar from '@coreui/react/src/components/navbar/CNavbar'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the component.string-
colorSets the color context of the component to one of CoreUI’s themed colors.'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string-
colorSchemeSets if the color of text should be colored for a light or dark dark background.'dark' | 'light'-
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>-
containerDefines optional container wrapping children elements.boolean | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'fluid'-
expandDefines the responsive breakpoint to determine when content collapses.boolean | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'-
placementPlace component in non-static positions.'fixed-top' | 'fixed-bottom' | 'sticky-top'-

CNavbarBrand#

1import { CNavbarBrand } from '@coreui/react'
2// or
3import CNavbarBrand from '@coreui/react/src/components/navbar/CNavbarBrand'
PropertyDescriptionTypeDefault
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>-
hrefThe href attribute specifies the URL of the page the link goes to.string-

CNavbarNav#

1import { CNavbarNav } from '@coreui/react'
2// or
3import CNavbarNav from '@coreui/react/src/components/navbar/CNavbarNav'
PropertyDescriptionTypeDefault
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>-

CNavbarText#

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

CNavbarToggler#

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