Documentation and examples of how to use CoreUI Angular navigation components.
Navigation available in CoreUI for Angular share general markup and styles, from the base .nav class to the active
and
disabled states. Swap modifier classes to switch between each style.
Examples
The base c-nav 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.
Base nav
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavItemComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-base',
templateUrl: './nav-base.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [NavComponent, NavItemComponent, NavLinkDirective, RouterLink]
})
export class NavBaseComponent {}<c-nav>
<c-nav-item>
<a [active]="true" [routerLink] cNavLink> Active </a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink disabled> Disabled </a>
</c-nav-item>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Classes are used throughout, so your markup can be super flexible. Use c-nav-item like above, or roll your own with
a c-nav element. Because the .nav uses display: flex, the cNavLink
behaves the same as c-nav-item would, but without the extra markup.
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-base-2',
templateUrl: './nav-base-2.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [NavComponent, NavLinkDirective, RouterLink]
})
export class NavBase2Component {}<c-nav role="navigation">
<a [active]="true" cNavLink routerLink>
Active
</a>
<a cNavLink routerLink>Link</a>
<a cNavLink routerLink>Link</a>
<a [disabled]="true" cNavLink routerLink>
Disabled
</a>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Change the style of c-nav 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:
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavItemComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-horizontal-alignment',
templateUrl: './nav-horizontal-alignment.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [NavComponent, NavItemComponent, NavLinkDirective, RouterLink]
})
export class NavHorizontalAlignmentComponent {}<c-nav class="justify-content-center">
<c-nav-item>
<a [active]="true" [routerLink] cNavLink>
Active
</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink disabled>
Disabled
</a>
</c-nav-item>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Right-aligned with .justify-content-end:
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavItemComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-horizontal-alignment-2',
templateUrl: './nav-horizontal-alignment-2.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [NavComponent, NavItemComponent, NavLinkDirective, RouterLink]
})
export class NavHorizontalAlignment2Component {}<c-nav class="justify-content-end">
<c-nav-item>
<a [active]="true" [routerLink] cNavLink>
Active
</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink disabled>
Disabled
</a>
</c-nav-item>
</c-nav>
:host {
.active {
text-decoration: underline;
}
}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 (ex. .flex-sm-column).
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavItemComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-vertical',
templateUrl: './nav-vertical.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [NavComponent, NavItemComponent, NavLinkDirective, RouterLink]
})
export class NavVerticalComponent {}<c-nav class="flex-column">
<c-nav-item>
<a [active]="true" [routerLink] cNavLink>
Active
</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [disabled]="true" [routerLink] cNavLink>
Disabled
</a>
</c-nav-item>
</c-nav>
:host {
.active {
text-decoration: underline;
}
}Tabs
Take the basic nav from above and add the variant="tabs" class to generate a tabbed interface
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-tabs',
templateUrl: './nav-tabs.component.html',
imports: [NavComponent, NavLinkDirective, RouterLink]
})
export class NavTabsComponent {}<c-nav variant="tabs">
<a [active]="true" [routerLink] cNavLink>Active</a>
<a [routerLink] cNavLink>Link</a>
<a [routerLink] cNavLink>Link</a>
<a [disabled]="true" [routerLink] cNavLink>Disabled</a>
</c-nav>
:host {
.active {
text-decoration: underline;
}
}Pills
Take that same HTML, but use variant="pills" instead:
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-pills',
templateUrl: './nav-pills.component.html',
imports: [NavComponent, NavLinkDirective, RouterLink]
})
export class NavPillsComponent {}<c-nav variant="pills">
<a [active]="true" [routerLink] cNavLink>Active</a>
<a [routerLink] cNavLink>Link</a>
<a [routerLink] cNavLink>Link</a>
<a [disabled]="true" [routerLink] cNavLink>Disabled</a>
</c-nav>
:host {
.active {
text-decoration: underline;
}
}Underline
Take that same HTML, but use variant=“underline”:
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-underline',
templateUrl: './nav-underline.component.html',
imports: [NavComponent, NavLinkDirective, RouterLink]
})
export class NavUnderlineComponent {}<c-nav variant="underline">
<a [active]="true" [routerLink] cNavLink>Active</a>
<a [routerLink] cNavLink>Link</a>
<a [routerLink] cNavLink>Link</a>
<a [disabled]="true" [routerLink] cNavLink>Disabled</a>
</c-nav>
:host {
.active {
text-decoration: underline;
}
}Enclosed
Added in v5.7.24Use variant="enclosed" to give your navigation items a subtle border and rounded styling.
import { Component } from '@angular/core';
import { NavComponent, NavItemComponent } from '@coreui/angular';
@Component({
selector: 'docs-nav-enclosed',
templateUrl: './nav-enclosed.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [NavComponent, NavItemComponent]
})
export class NavEnclosedComponent {}<c-nav variant="enclosed">
<c-nav-item [active]="true" href="#">Active</c-nav-item>
<c-nav-item href="#">Link</c-nav-item>
<c-nav-item href="#">Link</c-nav-item>
<c-nav-item [disabled]="true" href="#">Disabled</c-nav-item>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Enclosed pills
Added in v5.7.24Use variant="enclosed-pills" for a pill-style appearance of each nav item. It adds the .nav-enclosed styling on
top of the pill-shaped item borders.
import { Component } from '@angular/core';
import { NavComponent, NavItemComponent } from '@coreui/angular';
@Component({
selector: 'docs-nav-enclosed-pills',
templateUrl: './nav-enclosed-pills.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [NavComponent, NavItemComponent]
})
export class NavEnclosedPillsComponent {}<c-nav variant="enclosed-pills">
<c-nav-item [active]="true" href="#">Active</c-nav-item>
<c-nav-item href="#">Link</c-nav-item>
<c-nav-item href="#">Link</c-nav-item>
<c-nav-item [disabled]="true" href="#">Disabled</c-nav-item>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Link items
Added in v5.7.24Set href on c-nav-item and it renders the cNavLink anchor for you, forwarding active, disabled and
tabindex. Without href the item projects its content as is, so a router link keeps its own markup.
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavItemComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-link-items',
templateUrl: './nav-link-items.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [NavComponent, NavItemComponent, NavLinkDirective, RouterLink]
})
export class NavLinkItemsComponent {}<c-nav>
<c-nav-item [active]="true" href="#">Active</c-nav-item>
<c-nav-item [disabled]="true" href="#">Disabled</c-nav-item>
<c-nav-item>
<a [routerLink]="['./']" cNavLink>Link written by hand</a>
</c-nav-item>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Fill and justify
Force your c-nav contents to extend the full available width one of two modifier classes. To proportionately fill
all available space with your c-nav-item, use layout="fill".
Notice that all horizontal space is occupied, but not every nav item has the same width.
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavItemComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-fill-justify',
templateUrl: './nav-fill-justify.component.html',
imports: [NavComponent, NavItemComponent, NavLinkDirective, RouterLink]
})
export class NavFillJustifyComponent {}<c-nav layout="fill" variant="pills">
<c-nav-item>
<a [active]="true" [routerLink] cNavLink> Active </a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [routerLink] cNavLink disabled> Disabled </a>
</c-nav-item>
</c-nav>
:host {
.active {
text-decoration: underline;
}
}For equal-width elements, use layout="justified". All horizontal space will be occupied by nav links, but unlike the
fill above, every nav item will be the same width.
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-fill-justify-2',
templateUrl: './nav-fill-justify-2.component.html',
imports: [NavComponent, NavLinkDirective, RouterLink]
})
export class NavFillJustify2Component {}<c-nav layout="justified" variant="pills">
<a [active]="true" [routerLink] cNavLink>Active</a>
<a [routerLink] cNavLink>Link</a>
<a [routerLink] cNavLink>Link</a>
<a [disabled]="true" [routerLink] cNavLink>Disabled</a>
</c-nav>:host {
.active {
text-decoration: underline;
}
}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.
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NavComponent, NavLinkDirective } from '@coreui/angular';
@Component({
selector: 'docs-nav-working-with-flex-utilities',
templateUrl: './nav-working-with-flex-utilities.component.html',
imports: [NavComponent, NavLinkDirective, RouterLink]
})
export class NavWorkingWithFlexUtilitiesComponent {}<c-nav class="flex-column flex-sm-row" role="navigation" variant="pills">
<a [active]="true" [routerLink] cNavLink>Active</a>
<a [routerLink] cNavLink>Link</a>
<a [routerLink] cNavLink>Link</a>
<a [disabled]="true" [routerLink] cNavLink>Disabled</a>
</c-nav>
:host {
.active {
text-decoration: underline;
}
}Using dropdowns
Add dropdown menus with a little extra HTML.
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import {
DropdownComponent,
DropdownItemDirective,
DropdownMenuDirective,
DropdownToggleDirective,
NavComponent,
NavItemComponent,
NavLinkDirective
} from '@coreui/angular';
@Component({
selector: 'docs-nav-dropdowns',
templateUrl: './nav-dropdowns.component.html',
styleUrls: ['./nav-base.component.scss'],
imports: [
NavComponent,
NavItemComponent,
NavLinkDirective,
RouterLink,
DropdownComponent,
DropdownToggleDirective,
DropdownMenuDirective,
DropdownItemDirective
]
})
export class NavDropdownsComponent {}<c-nav>
<c-nav-item>
<a [active]="true" [routerLink] cNavLink>Active</a>
</c-nav-item>
<c-dropdown variant="nav-item">
<a [routerLink] cDropdownToggle cNavLink>Dropdown button</a>
<ul cDropdownMenu>
<li><a [routerLink] cDropdownItem>Action</a></li>
<li><a [routerLink] cDropdownItem>Another action</a></li>
<li><a [routerLink] cDropdownItem>Something else here</a></li>
</ul>
</c-dropdown>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [disabled]="true" [routerLink] cNavLink>Disabled</a>
</c-nav-item>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Tabs with dropdowns
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import {
DropdownComponent,
DropdownItemDirective,
DropdownMenuDirective,
DropdownToggleDirective,
NavComponent,
NavItemComponent,
NavLinkDirective
} from '@coreui/angular';
@Component({
selector: 'docs-nav-tabs-with-dropdowns',
templateUrl: './nav-tabs-with-dropdowns.component.html',
imports: [
NavComponent,
NavItemComponent,
NavLinkDirective,
RouterLink,
DropdownComponent,
DropdownToggleDirective,
DropdownMenuDirective,
DropdownItemDirective
]
})
export class NavTabsWithDropdownsComponent {}<c-nav variant="tabs">
<c-nav-item>
<a [active]="true" [routerLink] cNavLink>Active</a>
</c-nav-item>
<c-dropdown variant="nav-item">
<a [routerLink] cDropdownToggle cNavLink>Dropdown button</a>
<ul cDropdownMenu>
<li><a [routerLink] cDropdownItem>Action</a></li>
<li><a [routerLink] cDropdownItem>Another action</a></li>
<li><a [routerLink] cDropdownItem>Something else here</a></li>
</ul>
</c-dropdown>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [disabled]="true" [routerLink] cNavLink>Disabled</a>
</c-nav-item>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Pills with dropdowns
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import {
DropdownComponent,
DropdownItemDirective,
DropdownMenuDirective,
DropdownToggleDirective,
NavComponent,
NavItemComponent,
NavLinkDirective
} from '@coreui/angular';
@Component({
selector: 'docs-nav-pills-with-dropdowns',
templateUrl: './nav-pills-with-dropdowns.component.html',
imports: [
NavComponent,
NavItemComponent,
NavLinkDirective,
RouterLink,
DropdownComponent,
DropdownToggleDirective,
DropdownMenuDirective,
DropdownItemDirective
]
})
export class NavPillsWithDropdownsComponent {}<c-nav variant="pills">
<c-nav-item>
<a [active]="true" [routerLink] cNavLink>Active</a>
</c-nav-item>
<c-dropdown variant="nav-item">
<a [routerLink] cDropdownToggle cNavLink>Dropdown button</a>
<ul cDropdownMenu>
<li><a [routerLink] cDropdownItem>Action</a></li>
<li><a [routerLink] cDropdownItem>Another action</a></li>
<li><a [routerLink] cDropdownItem>Something else here</a></li>
</ul>
</c-dropdown>
<c-nav-item>
<a [routerLink] cNavLink>Link</a>
</c-nav-item>
<c-nav-item>
<a [disabled]="true" [routerLink] cNavLink>Disabled</a>
</c-nav-item>
</c-nav>:host {
.active {
text-decoration: underline;
}
}Regarding accessibility
c-nav carries role="navigation" by default, so a nav used as a navigation bar is announced as such without extra
markup. Change it with the role input where the nav is not a navigation landmark — several navigation landmarks on
one page should be labelled (aria-label) so they can be told apart.
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.
API reference
Nav Module
import { NavModule } from '@coreui/angular';
@NgModule({
imports: [NavModule,]
})
export class AppModule() { }c-nav
component
import { NavComponent } from '@coreui/angular'c-nav-group
component
import { NavGroupComponent } from '@coreui/angular'Props
Events
c-nav-group-items
component
import { NavGroupItemsComponent } from '@coreui/angular'| Property | Default | Type |
|---|---|---|
| compact | false | boolean |
Make nav group items more compact by cutting all | ||
c-nav-item
component
import { NavItemComponent } from '@coreui/angular'c-nav-title
component
import { NavTitleComponent } from '@coreui/angular'cNavLink
directive
import { NavLinkDirective } from '@coreui/angular'