React Navbar Component

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

Other frameworks

CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.

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#

const [visible, setVisible] = useState(false)
return (
<>
<CNavbar expand="lg" colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CNavbarToggler onClick={() => setVisible(!visible)} />
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav>
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CDropdown variant="nav-item" popper={false}>
<CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem href="#">Action</CDropdownItem>
<CDropdownItem href="#">Another action</CDropdownItem>
<CDropdownDivider />
<CDropdownItem href="#">Something else here</CDropdownItem>
</CDropdownMenu>
</CDropdown>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="success" variant="outline">
Search
</CButton>
</CForm>
</CCollapse>
</CContainer>
</CNavbar>
</>
)

Brand#

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


<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
</CContainer>
</CNavbar>
<br/>
<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand className="mb-0 h1">Navbar</CNavbarBrand>
</CContainer>
</CNavbar>

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

<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">
<img src={CoreUISignetImg} alt="" width="22" height="24" />
</CNavbarBrand>
</CContainer>
</CNavbar>
<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">
<img
src={CoreUISignetImg}
alt=""
width="22"
height="24"
className="d-inline-block align-top"
/> CoreUI
</CNavbarBrand>
</CContainer>
</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.

const [visible, setVisible] = useState(false)
return (
<>
<CNavbar expand="lg" colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav>
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Features</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Pricing</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
</CCollapse>
</CContainer>
</CNavbar>
</>
)

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

const [visible, setVisible] = useState(false)
return (
<>
<CNavbar expand="lg" colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav component="nav">
<CNavLink href="#" active>
Home
</CNavLink>
<CNavLink href="#">Features</CNavLink>
<CNavLink href="#">Pricing</CNavLink>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavbarNav>
</CCollapse>
</CContainer>
</CNavbar>
</>
)

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

const [visible, setVisible] = useState(false)
return (
<>
<CNavbar expand="lg" colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav>
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Features</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Pricing</CNavLink>
</CNavItem>
<CDropdown variant="nav-item" popper={false}>
<CDropdownToggle>Dropdown link</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem href="#">Action</CDropdownItem>
<CDropdownItem href="#">Another action</CDropdownItem>
<CDropdownDivider />
<CDropdownItem href="#">Something else here</CDropdownItem>
</CDropdownMenu>
</CDropdown>
</CNavbarNav>
</CCollapse>
</CContainer>
</CNavbar>
</>
)

Forms#

Place various form controls and components within a navbar:

<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="success" variant="outline">
Search
</CButton>
</CForm>
</CContainer>
</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.

<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="success" variant="outline">
Search
</CButton>
</CForm>
</CContainer>
</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.

<CNavbar colorScheme="light" className="bg-light">
<CForm className="container-fluid">
<CInputGroup>
<CInputGroupText id="basic-addon1">@</CInputGroupText>
<CFormInput placeholder="Username" aria-label="Username" aria-describedby="basic-addon1" />
</CInputGroup>
</CForm>
</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.

<CNavbar colorScheme="light" className="bg-light">
<CForm className="container-fluid justify-content-start">
<CButton type="button" color="success" variant="outline" className="me-2">
Main button
</CButton>
<CButton type="button" color="secondary" variant="outline" size="sm">
Smaller button
</CButton>
</CForm>
</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.

<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarText>Navbar text with an inline element</CNavbarText>
</CContainer>
</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.

const [visible, setVisible] = useState(false)
return (
<>
<CNavbar expand="lg" colorScheme="dark" className="bg-dark">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav>
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CDropdown variant="nav-item" popper={false}>
<CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem href="#">Action</CDropdownItem>
<CDropdownItem href="#">Another action</CDropdownItem>
<CDropdownDivider />
<CDropdownItem href="#">Something else here</CDropdownItem>
</CDropdownMenu>
</CDropdown>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="light" variant="outline">
Search
</CButton>
</CForm>
</CCollapse>
</CContainer>
</CNavbar>
<br />
<CNavbar expand="lg" colorScheme="dark" className="bg-primary">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav>
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CDropdown variant="nav-item" popper={false}>
<CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem href="#">Action</CDropdownItem>
<CDropdownItem href="#">Another action</CDropdownItem>
<CDropdownDivider />
<CDropdownItem href="#">Something else here</CDropdownItem>
</CDropdownMenu>
</CDropdown>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="light" variant="outline">
Search
</CButton>
</CForm>
</CCollapse>
</CContainer>
</CNavbar>
<br />
<CNavbar expand="lg" colorScheme="light" style={{ backgroundColor: '#e3f2fd' }}>
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav>
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CDropdown variant="nav-item" popper={false}>
<CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem href="#">Action</CDropdownItem>
<CDropdownItem href="#">Another action</CDropdownItem>
<CDropdownDivider />
<CDropdownItem href="#">Something else here</CDropdownItem>
</CDropdownMenu>
</CDropdown>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="primary" variant="outline">
Search
</CButton>
</CForm>
</CCollapse>
</CContainer>
</CNavbar>
</>
)

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.

<CContainer>
<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
</CContainer>
</CNavbar>
</CContainer>

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

<CNavbar colorScheme="light" className="bg-light">
<CContainer breakpoint="md">
<CNavbarBrand href="#">Navbar</CNavbarBrand>
</CContainer>
</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.

<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Default</CNavbarBrand>
</CContainer>
</CNavbar>
<CNavbar colorScheme="light" className="bg-light" placement="fixed-top">
<CContainer fluid>
<CNavbarBrand href="#">Fixed top</CNavbarBrand>
</CContainer>
</CNavbar>
<CNavbar colorScheme="light" className="bg-light" placement="fixed-bottom">
<CContainer fluid>
<CNavbarBrand href="#">Fixed bottom</CNavbarBrand>
</CContainer>
</CNavbar>
<CNavbar colorScheme="light" className="bg-light" placement="sticky-top">
<CContainer fluid>
<CNavbarBrand href="#">Sticky top</CNavbarBrand>
</CContainer>
</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:

const [visible, setVisible] = useState(false)
return (
<>
<CNavbar expand="lg" colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarBrand href="#">Hidden brand</CNavbarBrand>
<CNavbarNav className="me-auto mb-2 mb-lg-0">
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="success" variant="outline">
Search
</CButton>
</CForm>
</CCollapse>
</CContainer>
</CNavbar>
</>
)

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

const [visible, setVisible] = useState(false)
return (
<>
<CNavbar expand="lg" colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav className="me-auto mb-2 mb-lg-0">
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="success" variant="outline">
Search
</CButton>
</CForm>
</CCollapse>
</CContainer>
</CNavbar>
</>
)

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

const [visible, setVisible] = useState(false)
return (
<>
<CNavbar expand="lg" colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarToggler
aria-label="Toggle navigation"
aria-expanded={visible}
onClick={() => setVisible(!visible)}
/>
<CNavbarBrand href="#">Navbar</CNavbarBrand>
<CCollapse className="navbar-collapse" visible={visible}>
<CNavbarNav className="me-auto mb-2 mb-lg-0">
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="success" variant="outline">
Search
</CButton>
</CForm>
</CCollapse>
</CContainer>
</CNavbar>
</>
)

External content#

Sometimes you want to use the collapse plugin to trigger a container element for content that structurally sits outside of the <CNavbar>.

const [visible, setVisible] = useState(false)
return (
<>
<CCollapse id="navbarToggleExternalContent" visible={visible}>
<div className="bg-dark p-4">
<h5 className="text-white h4">Collapsed content</h5>
<span className="text-medium-emphasis-inverse">Toggleable via the navbar brand.</span>
</div>
</CCollapse>
<CNavbar colorScheme="dark" className="bg-dark">
<CContainer fluid>
<CNavbarToggler
aria-controls="navbarToggleExternalContent"
aria-label="Toggle navigation"
onClick={() => setVisible(!visible)}
/>
</CContainer>
</CNavbar>
</>
)

Offcanvas#

Transform your expanding and collapsing navbar into an offcanvas drawer with the offcanvas plugin. We extend both the offcanvas default styles and use our expand="*" prop to create a dynamic and flexible navigation sidebar.

In the example below, to create an offcanvas navbar that is always collapsed across all breakpoints, omit the expand="*" prop entirely.

const [visible, setVisible] = useState(false)
return (
<CNavbar colorScheme="light" className="bg-light">
<CContainer fluid>
<CNavbarBrand>Offcanvas navbar</CNavbarBrand>
<CNavbarToggler
aria-controls="offcanvasNavbar"
aria-label="Toggle navigation"
onClick={() => setVisible(!visible)}
/>
<COffcanvas id="offcanvasNavbar" placement="end" portal={false} visible={visible} onHide={() => setVisible(false)}>
<COffcanvasHeader>
<COffcanvasTitle>Offcanvas</COffcanvasTitle>
<CCloseButton className="text-reset" onClick={() => setVisible(false)} />
</COffcanvasHeader>
<COffcanvasBody>
<CNavbarNav>
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CDropdown variant="nav-item" popper={false}>
<CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem href="#">Action</CDropdownItem>
<CDropdownItem href="#">Another action</CDropdownItem>
<CDropdownDivider />
<CDropdownItem href="#">Something else here</CDropdownItem>
</CDropdownMenu>
</CDropdown>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="success" variant="outline">
Search
</CButton>
</CForm>
</COffcanvasBody>
</COffcanvas>
</CContainer>
</CNavbar>
)

To create an offcanvas navbar that expands into a normal navbar at a specific breakpoint like xxl, use expand="xxl" property.

const [visible, setVisible] = useState(false)
return (
<CNavbar colorScheme="light" className="bg-light" expand="xxl">
<CNavbarBrand>Offcanvas navbar</CNavbarBrand>
<CContainer fluid>
<CNavbarToggler
aria-controls="offcanvasNavbar2"
aria-label="Toggle navigation"
onClick={() => setVisible(!visible)}
/>
<COffcanvas id="offcanvasNavbar2" placement="end" portal={false} visible={visible} onHide={() => setVisible(false)}>
<COffcanvasHeader>
<COffcanvasTitle>Offcanvas</COffcanvasTitle>
<CCloseButton className="text-reset" onClick={() => setVisible(false)} />
</COffcanvasHeader>
<COffcanvasBody>
<CNavbarNav>
<CNavItem>
<CNavLink href="#" active>
Home
</CNavLink>
</CNavItem>
<CNavItem>
<CNavLink href="#">Link</CNavLink>
</CNavItem>
<CDropdown variant="nav-item" popper={false}>
<CDropdownToggle color="secondary">Dropdown button</CDropdownToggle>
<CDropdownMenu>
<CDropdownItem href="#">Action</CDropdownItem>
<CDropdownItem href="#">Another action</CDropdownItem>
<CDropdownDivider />
<CDropdownItem href="#">Something else here</CDropdownItem>
</CDropdownMenu>
</CDropdown>
<CNavItem>
<CNavLink href="#" disabled>
Disabled
</CNavLink>
</CNavItem>
</CNavbarNav>
<CForm className="d-flex">
<CFormInput type="search" className="me-2" placeholder="Search" />
<CButton type="submit" color="success" variant="outline">
Search
</CButton>
</CForm>
</COffcanvasBody>
</COffcanvas>
</CContainer>
</CNavbar>
)

Customizing#

CSS variables#

React navbars use local CSS variables on .navbar for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.

--cui-navbar-padding-x: #{if($navbar-padding-x == null, 0, $navbar-padding-x)};
--cui-navbar-padding-y: #{$navbar-padding-y};
--cui-navbar-color: #{$navbar-light-color};
--cui-navbar-hover-color: #{$navbar-light-hover-color};
--cui-navbar-disabled-color: #{$navbar-light-disabled-color};
--cui-navbar-active-color: #{$navbar-light-active-color};
--cui-navbar-brand-padding-y: #{$navbar-brand-padding-y};
--cui-navbar-brand-margin-end: #{$navbar-brand-margin-end};
--cui-navbar-brand-font-size: #{$navbar-brand-font-size};
--cui-navbar-brand-color: #{$navbar-light-brand-color};
--cui-navbar-brand-hover-color: #{$navbar-light-brand-hover-color};
--cui-navbar-nav-link-padding-x: #{$navbar-nav-link-padding-x};
--cui-navbar-toggler-padding-y: #{$navbar-toggler-padding-y};
--cui-navbar-toggler-padding-x: #{$navbar-toggler-padding-x};
--cui-navbar-toggler-font-size: #{$navbar-toggler-font-size};
--cui-navbar-toggler-icon-bg: #{escape-svg($navbar-light-toggler-icon-bg)};
--cui-navbar-toggler-border-color: #{$navbar-light-toggler-border-color};
--cui-navbar-toggler-border-radius: #{$navbar-toggler-border-radius};
--cui-navbar-toggler-focus-width: #{$navbar-toggler-focus-width};
--cui-navbar-toggler-transition: #{$navbar-toggler-transition};

Some additional CSS variables are also present on .navbar-nav:

--cui-nav-link-padding-x: 0;
--cui-nav-link-padding-y: #{$nav-link-padding-y};
@include rfs($nav-link-font-size, --cui-nav-link-font-size);
--cui-nav-link-font-weight: #{$nav-link-font-weight};
--cui-nav-link-color: var(--cui-navbar-color);
--cui-nav-link-hover-color: var(--cui-navbar-hover-color);
--cui-nav-link-disabled-color: var(--cui-navbar-disabled-color);

Customization through CSS variables can be seen on the .navbar-dark class where we override specific values without adding duplicate CSS selectors.

--cui-navbar-color: #{$navbar-dark-color};
--cui-navbar-hover-color: #{$navbar-dark-hover-color};
--cui-navbar-disabled-color: #{$navbar-dark-disabled-color};
--cui-navbar-active-color: #{$navbar-dark-active-color};
--cui-navbar-brand-color: #{$navbar-dark-brand-color};
--cui-navbar-brand-hover-color: #{$navbar-dark-brand-hover-color};
--cui-navbar-toggler-border-color: #{$navbar-dark-toggler-border-color};
--cui-navbar-toggler-icon-bg: #{escape-svg($navbar-dark-toggler-icon-bg)};

How to use CSS variables#

const vars = {
'--my-css-var': 10,
'--my-another-css-var': "red"
}
return <CNavbar style={vars}>...</CNavbar>

SASS variables#

Variables for all navbars:

$navbar-padding-y: $spacer * .5 !default;
$navbar-padding-x: null !default;
$navbar-nav-link-padding-x: .5rem !default;
$navbar-brand-font-size: $font-size-lg !default;
// Compute the navbar-brand padding-y so the navbar-brand will have the same height as navbar-text and nav-link
$nav-link-height: $font-size-base * $line-height-base + $nav-link-padding-y * 2 !default;
$navbar-brand-height: $navbar-brand-font-size * $line-height-base !default;
$navbar-brand-padding-y: ($nav-link-height - $navbar-brand-height) * .5 !default;
$navbar-brand-margin-end: 1rem !default;
$navbar-toggler-padding-y: .25rem !default;
$navbar-toggler-padding-x: .75rem !default;
$navbar-toggler-font-size: $font-size-lg !default;
$navbar-toggler-border-radius: $btn-border-radius !default;
$navbar-toggler-focus-width: $btn-focus-width !default;
$navbar-toggler-transition: box-shadow .15s ease-in-out !default;
$navbar-light-color: rgba(var(--cui-emphasis-color-rgb), .65) !default;
$navbar-light-hover-color: rgba(var(--cui-emphasis-color-rgb), .8) !default;
$navbar-light-active-color: rgba(var(--cui-emphasis-color-rgb), 1) !default;
$navbar-light-disabled-color: rgba(var(--cui-emphasis-color-rgb), .3) !default;
$navbar-light-icon-color: rgba($body-color, .75) !default;
$navbar-light-toggler-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-light-icon-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>") !default;
$navbar-light-toggler-border-color: rgba(var(--cui-emphasis-color-rgb), .15) !default;
$navbar-light-brand-color: $navbar-light-active-color !default;
$navbar-light-brand-hover-color: $navbar-light-active-color !default;

SASS loops#

Responsive navbar expand/collapse classes (e.g., .navbar-expand-lg) are combined with the $breakpoints map and generated through a loop in scss/_navbar.scss.

// Generate series of `.navbar-expand-*` responsive classes for configuring
// where your navbar collapses.
.navbar-expand {
@each $breakpoint in map-keys($grid-breakpoints) {
$next: breakpoint-next($breakpoint, $grid-breakpoints);
$infix: breakpoint-infix($next, $grid-breakpoints);
// stylelint-disable-next-line scss/selector-no-union-class-name
&#{$infix} {
@include media-breakpoint-up($next) {
flex-wrap: nowrap;
justify-content: flex-start;
.navbar-nav {
flex-direction: row;
.dropdown-menu {
position: absolute;
}
.nav-link {
padding-right: var(--cui-navbar-nav-link-padding-x);
padding-left: var(--cui-navbar-nav-link-padding-x);
}
}
.navbar-nav-scroll {
overflow: visible;
}
.navbar-collapse {
display: flex !important; // stylelint-disable-line declaration-no-important
flex-basis: auto;
}
.navbar-toggler {
display: none;
}
.offcanvas {
// stylelint-disable declaration-no-important
position: static;
z-index: auto;
flex-grow: 1;
width: auto !important;
height: auto !important;
visibility: visible !important;
background-color: transparent !important;
border: 0 !important;
transform: none !important;
@include box-shadow(none);
@include transition(none);
// stylelint-enable declaration-no-important
.offcanvas-header {
display: none;
}
.offcanvas-body {
display: flex;
flex-grow: 0;
padding: 0;
overflow-y: visible;
}
}
}
}
}
}

API#

CNavbar#

import { CNavbar } from '@coreui/react'
// or
import 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#

import { CNavbarBrand } from '@coreui/react'
// or
import 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#

import { CNavbarNav } from '@coreui/react'
// or
import 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#

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

CNavbarToggler#

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