Movatterモバイル変換


[0]ホーム

URL:


Framework:


Hire Us Get CoreUI PRO all-access

Bootstrap 5 Navs and Tabs

Navs and tabs

Documentation and examples for how to use CoreUI for Bootstrap’s included navigation components.

🤖 Looking for the LLM-optimized version?View llm.md

Other frameworks

CoreUI components are available as native Angular, React, and Vue components. To learn more please visit the following pages.

On this page

Base nav

Navigation available in Bootstrap 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.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.

The base.nav component does not include any.active state. The following examples include the class, mainly to demonstrate that this particular class does not trigger any special styling.

To convey the active state to assistive technologies, use thearia-current attribute — using thepage value for current page, ortrue for the current item in a set.

html
<ulclass="nav"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

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 usesdisplay: flex, the nav links behave the same as nav items would, but without the extra markup.

html
<navclass="nav"><aclass="nav-link active"aria-current="page"href="#">Active</a><aclass="nav-link"href="#">Link</a><aclass="nav-link"href="#">Link</a><aclass="nav-link disabled"aria-disabled="true">Disabled</a></nav>

Available styles

Change the style of.navs component with modifiers and utilities. Mix and match as needed, or build your own.

Horizontal alignment

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

Centered with.justify-content-center:

html
<ulclass="nav justify-content-center"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Right-aligned with.justify-content-end:

html
<ulclass="nav justify-content-end"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

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).

html
<ulclass="nav flex-column"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

As always, vertical navigation is possible without<ul>s, too.

html
<navclass="nav flex-column"><aclass="nav-link active"aria-current="page"href="#">Active</a><aclass="nav-link"href="#">Link</a><aclass="nav-link"href="#">Link</a><aclass="nav-link disabled"aria-disabled="true">Disabled</a></nav>

Tabs

Takes the basic nav from above and adds the.nav-tabs class to generate a tabbed interface. Use them to create tabbable regions with ourtab JavaScript plugin.

html
<ulclass="nav nav-tabs"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Pills

Take that same HTML, but use.nav-pills instead:

html
<ulclass="nav nav-pills"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Underline

Take that same HTML, but use.nav-underline instead:

html
<ulclass="nav nav-underline"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Underline border

Take that same HTML, but use.nav-underline-border instead:

html
<ulclass="nav nav-underline-border"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Enclosed

Use the.nav-enclosed class to give your navigation items a subtle border and rounded styling.

html
<ulclass="nav nav-enclosed"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Enclosed pills

Combine.nav-enclosed with.nav-enclosed-pills to achieve a pill-style appearance for each nav item, using pill-shaped borders and smoother outlines.

html
<ulclass="nav nav-enclosed nav-enclosed-pills"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Fill and justify

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

html
<ulclass="nav nav-pills nav-fill"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Much longer nav link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

When using a<nav>-based navigation, you can safely omit.nav-item as only.nav-link is required for styling<a> elements.

html
<navclass="nav nav-pills nav-fill"><aclass="nav-link active"aria-current="page"href="#">Active</a><aclass="nav-link"href="#">Much longer nav link</a><aclass="nav-link"href="#">Link</a><aclass="nav-link disabled"aria-disabled="true">Disabled</a></nav>

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

html
<ulclass="nav nav-pills nav-justified"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item"><aclass="nav-link"href="#">Much longer nav link</a></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Similar to the.nav-fill example using a<nav>-based navigation.

html
<navclass="nav nav-pills nav-justified"><aclass="nav-link active"aria-current="page"href="#">Active</a><aclass="nav-link"href="#">Much longer nav link</a><aclass="nav-link"href="#">Link</a><aclass="nav-link disabled"aria-disabled="true">Disabled</a></nav>

Working with flex utilities

If you need responsive nav variations, consider using a series offlexbox 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.

html
<navclass="nav nav-pills flex-column flex-sm-row"><aclass="flex-sm-fill text-sm-center nav-link active"aria-current="page"href="#">Active</a><aclass="flex-sm-fill text-sm-center nav-link"href="#">Longer nav link</a><aclass="flex-sm-fill text-sm-center nav-link"href="#">Link</a><aclass="flex-sm-fill text-sm-center nav-link disabled"aria-disabled="true">Disabled</a></nav>

Regarding accessibility

If you’re using navs to provide a navigation bar, be sure to add arole="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, shouldnot be givenrole="tablist",role="tab" orrole="tabpanel" attributes. These are only appropriate for dynamic tabbed interfaces, as described in theARIA Authoring Practices Guide tabs pattern. SeeJavaScript behavior for dynamic tabbed interfaces in this section for an example. Thearia-current attribute is not necessary on dynamic tabbed interfaces since our JavaScript handles the selected state by addingaria-selected="true" on the active tab.

Using dropdowns

Add dropdown menus with a little extra HTML and thedropdowns JavaScript plugin.

Tabs with dropdowns

html
<ulclass="nav nav-tabs"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item dropdown"><aclass="nav-link dropdown-toggle"data-coreui-toggle="dropdown"href="#"role="button"aria-expanded="false">Dropdown</a><ulclass="dropdown-menu"><li><aclass="dropdown-item"href="#">Action</a></li><li><aclass="dropdown-item"href="#">Another action</a></li><li><aclass="dropdown-item"href="#">Something else here</a></li><li><hrclass="dropdown-divider"></li><li><aclass="dropdown-item"href="#">Separated link</a></li></ul></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

Pills with dropdowns

html
<ulclass="nav nav-pills"><liclass="nav-item"><aclass="nav-link active"aria-current="page"href="#">Active</a></li><liclass="nav-item dropdown"><aclass="nav-link dropdown-toggle"data-coreui-toggle="dropdown"href="#"role="button"aria-expanded="false">Dropdown</a><ulclass="dropdown-menu"><li><aclass="dropdown-item"href="#">Action</a></li><li><aclass="dropdown-item"href="#">Another action</a></li><li><aclass="dropdown-item"href="#">Something else here</a></li><li><hrclass="dropdown-divider"></li><li><aclass="dropdown-item"href="#">Separated link</a></li></ul></li><liclass="nav-item"><aclass="nav-link"href="#">Link</a></li><liclass="nav-item"><aclass="nav-link disabled"aria-disabled="true">Disabled</a></li></ul>

JavaScript behavior

Heads up! In our documentation, all examples showstandard CoreUI implementation. If you are using aBootstrap-compatible version of CoreUI, remember to use the following changes:

  • In the constructor, please usebootstrap instead ofcoreui. For example,new bootstrap.Alert(...) instead ofnew coreui.Alert(...)
  • In events, please usebs instead ofcoreui, for exampleclose.bs.alert instead ofclose.coreui.alert
  • In data attributes, please usebs instead ofcoreui. For example,data-bs-toggle="..." instead ofdata-coreui-toggle="..."

Use the tab JavaScript plugin—include it individually or through the compiledcoreui.js file—to extend our navigational tabs and pills to create tabbable panes of local content, even via dropdown menus.

Dynamic tabbed interfaces, as described in theWAIARIA Authoring Practices, requirerole="tablist",role="tab",role="tabpanel", and additionalaria- attributes in order to convey their structure, functionality and current state to users of assistive technologies (such as screen readers). As a best practice, we recommend using<button> elements for the tabs, as these are controls that trigger a dynamic change, rather than links that navigate to a new page or location.

Note that dynamic tabbed interfaces shouldnot 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.

This is some placeholder content theHome tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theProfile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theContact tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theDisabled tab's associated content.

<ulclass="nav nav-tabs"id="myTab"role="tablist"><liclass="nav-item"role="presentation"><buttonclass="nav-link active"id="home-tab"data-coreui-toggle="tab"data-coreui-target="#home"type="button"role="tab"aria-controls="home"aria-selected="true">Home</button></li><liclass="nav-item"role="presentation"><buttonclass="nav-link"id="profile-tab"data-coreui-toggle="tab"data-coreui-target="#profile"type="button"role="tab"aria-controls="profile"aria-selected="false">Profile</button></li><liclass="nav-item"role="presentation"><buttonclass="nav-link"id="contact-tab"data-coreui-toggle="tab"data-coreui-target="#contact"type="button"role="tab"aria-controls="contact"aria-selected="false">Contact</button></li></ul><divclass="tab-content"id="myTabContent"><divclass="tab-pane fade show active"id="home-tab-pane"role="tabpanel"aria-labelledby="home-tab"tabindex="0">...</div><divclass="tab-pane fade"id="profile-tab-pane"role="tabpanel"aria-labelledby="profile-tab"tabindex="0">...</div><divclass="tab-pane fade"id="contact-tab-pane"role="tabpanel"aria-labelledby="contact-tab"tabindex="0">...</div><divclass="tab-pane fade"id="disabled-tab-pane"role="tabpanel"aria-labelledby="disabled-tab"tabindex="0">...</div></div>

To help fit your needs, this works with<ul>-based markup, as shown above, or with any arbitrary “roll your own” markup. Note that if you’re using<nav>, you shouldn’t addrole="tablist" directly to it, as this would override the element’s native role as a navigation landmark. Instead, switch to an alternative element (in the example below, a simple<div>) and wrap the<nav> around it.

This is some placeholder content theHome tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theProfile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theContact tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theDisabled tab's associated content.

<nav><divclass="nav nav-tabs"id="nav-tab"role="tablist"><buttonclass="nav-link active"id="nav-home-tab"data-coreui-toggle="tab"data-coreui-target="#nav-home"type="button"role="tab"aria-controls="nav-home"aria-selected="true">Home</button><buttonclass="nav-link"id="nav-profile-tab"data-coreui-toggle="tab"data-coreui-target="#nav-profile"type="button"role="tab"aria-controls="nav-profile"aria-selected="false">Profile</button><buttonclass="nav-link"id="nav-contact-tab"data-coreui-toggle="tab"data-coreui-target="#nav-contact"type="button"role="tab"aria-controls="nav-contact"aria-selected="false">Contact</button></div></nav><divclass="tab-content"id="nav-tabContent"><divclass="tab-pane fade show active"id="nav-home"role="tabpanel"aria-labelledby="nav-home-tab"tabindex="0">...</div><divclass="tab-pane fade"id="nav-profile"role="tabpanel"aria-labelledby="nav-profile-tab"tabindex="0">...</div><divclass="tab-pane fade"id="nav-contact"role="tabpanel"aria-labelledby="nav-contact-tab"tabindex="0">...</div><divclass="tab-pane fade"id="nav-disabled"role="tabpanel"aria-labelledby="nav-disabled-tab"tabindex="0">...</div></div>

The tabs plugin also works with pills.

This is some placeholder content theHome tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theProfile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theContact tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theDisabled tab's associated content.

<ulclass="nav nav-pills mb-3"id="pills-tab"role="tablist"><liclass="nav-item"role="presentation"><buttonclass="nav-link active"id="pills-home-tab"data-coreui-toggle="pill"data-coreui-target="#pills-home"type="button"role="tab"aria-controls="pills-home"aria-selected="true">Home</button></li><liclass="nav-item"role="presentation"><buttonclass="nav-link"id="pills-profile-tab"data-coreui-toggle="pill"data-coreui-target="#pills-profile"type="button"role="tab"aria-controls="pills-profile"aria-selected="false">Profile</button></li><liclass="nav-item"role="presentation"><buttonclass="nav-link"id="pills-contact-tab"data-coreui-toggle="pill"data-coreui-target="#pills-contact"type="button"role="tab"aria-controls="pills-contact"aria-selected="false">Contact</button></li><liclass="nav-item"role="presentation"><buttonclass="nav-link"id="pills-disabled-tab"data-coreui-toggle="pill"data-coreui-target="#pills-disabled"type="button"role="tab"aria-controls="pills-disabled"aria-selected="false"disabled>Disabled</button></li></ul><divclass="tab-content"id="pills-tabContent"><divclass="tab-pane fade show active"id="pills-home"role="tabpanel"aria-labelledby="pills-home-tab"tabindex="0">...</div><divclass="tab-pane fade"id="pills-profile"role="tabpanel"aria-labelledby="pills-profile-tab"tabindex="0">...</div><divclass="tab-pane fade"id="pills-contact"role="tabpanel"aria-labelledby="pills-contact-tab"tabindex="0">...</div><divclass="tab-pane fade"id="pills-disabled"role="tabpanel"aria-labelledby="pills-disabled-tab"tabindex="0">...</div></div>

And with vertical pills. Ideally, for vertical tabs, you should also addaria-orientation="vertical" to the tab list container.

This is some placeholder content theHome tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theProfile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theDisabled tab's associated content.

This is some placeholder content theMessages tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

This is some placeholder content theSettings tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other.nav-powered navigation.

<divclass="d-flex align-items-start"><divclass="nav flex-column nav-pills me-3"id="v-pills-tab"role="tablist"aria-orientation="vertical"><buttonclass="nav-link active"id="v-pills-home-tab"data-coreui-toggle="pill"data-coreui-target="#v-pills-home"type="button"role="tab"aria-controls="v-pills-home"aria-selected="true">Home</button><buttonclass="nav-link"id="v-pills-profile-tab"data-coreui-toggle="pill"data-coreui-target="#v-pills-profile"type="button"role="tab"aria-controls="v-pills-profile"aria-selected="false">Profile</button><buttonclass="nav-link"id="v-pills-messages-tab"data-coreui-toggle="pill"data-coreui-target="#v-pills-messages"type="button"role="tab"aria-controls="v-pills-messages"aria-selected="false">Messages</button><buttonclass="nav-link"id="v-pills-settings-tab"data-coreui-toggle="pill"data-coreui-target="#v-pills-settings"type="button"role="tab"aria-controls="v-pills-settings"aria-selected="false">Settings</button></div><divclass="tab-content"id="v-pills-tabContent"><divclass="tab-pane fade show active"id="v-pills-home"role="tabpanel"aria-labelledby="v-pills-home-tab"tabindex="0">...</div><divclass="tab-pane fade"id="v-pills-profile"role="tabpanel"aria-labelledby="v-pills-profile-tab"tabindex="0">...</div><divclass="tab-pane fade"id="v-pills-disabled"role="tabpanel"aria-labelledby="v-pills-disabled-tab"tabindex="0">...</div><divclass="tab-pane fade"id="v-pills-messages"role="tabpanel"aria-labelledby="v-pills-messages-tab"tabindex="0">...</div><divclass="tab-pane fade"id="v-pills-settings"role="tabpanel"aria-labelledby="v-pills-settings-tab"tabindex="0">...</div></div></div>

Accessibility

Dynamic tabbed interfaces, as described in theARIA Authoring Practices Guide tabs pattern, requirerole="tablist",role="tab",role="tabpanel", and additionalaria- attributes in order to convey their structure, functionality, and current state to users of assistive technologies (such as screen readers). As a best practice, we recommend using<button> elements for the tabs, as these are controls that trigger a dynamic change, rather than links that navigate to a new page or location.

In line with the ARIA Authoring Practices pattern, only the currently active tab receives keyboard focus. When the JavaScript plugin is initialized, it will settabindex="-1" on all inactive tab controls. Once the currently active tab has focus, the cursor keys activate the previous/next tab, with the plugin changing therovingtabindex accordingly. However, note that the JavaScript plugin does not distinguish between horizontal and vertical tab lists when it comes to cursor key interactions: regardless of the tab list’s orientation, both the upand left cursor go to the previous tab, and downand right cursor go to the next tab.

In general, to facilitate keyboard navigation, it’s recommended to make the tab panels themselves focusable as well, unless the first element containing meaningful content inside the tab panel is already focusable. The JavaScript plugin does not try to handle this aspect—where appropriate, you’ll need to explicitly make your tab panels focusable by addingtabindex="0" in your markup.
The tab JavaScript plugindoes not support tabbed interfaces that contain dropdown menus, as these cause 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.

Using data attributes

You can activate a tab or pill navigation without writing any JavaScript by simply specifyingdata-coreui-toggle="tab" ordata-coreui-toggle="pill" on an element. Use these data attributes on.nav-tabs or.nav-pills.

<!-- Nav tabs --><ulclass="nav nav-tabs"id="myTab"role="tablist"><liclass="nav-item"role="presentation"><buttonclass="nav-link active"id="home-tab"data-coreui-toggle="tab"data-coreui-target="#home"type="button"role="tab"aria-controls="home"aria-selected="true">Home</button></li><liclass="nav-item"role="presentation"><buttonclass="nav-link"id="profile-tab"data-coreui-toggle="tab"data-coreui-target="#profile"type="button"role="tab"aria-controls="profile"aria-selected="false">Profile</button></li><liclass="nav-item"role="presentation"><buttonclass="nav-link"id="messages-tab"data-coreui-toggle="tab"data-coreui-target="#messages"type="button"role="tab"aria-controls="messages"aria-selected="false">Messages</button></li><liclass="nav-item"role="presentation"><buttonclass="nav-link"id="settings-tab"data-coreui-toggle="tab"data-coreui-target="#settings"type="button"role="tab"aria-controls="settings"aria-selected="false">Settings</button></li></ul><!-- Tab panes --><divclass="tab-content"><divclass="tab-pane active"id="home"role="tabpanel"aria-labelledby="home-tab"tabindex="0">...</div><divclass="tab-pane"id="profile"role="tabpanel"aria-labelledby="profile-tab"tabindex="0">...</div><divclass="tab-pane"id="messages"role="tabpanel"aria-labelledby="messages-tab"tabindex="0">...</div><divclass="tab-pane"id="settings"role="tabpanel"aria-labelledby="settings-tab"tabindex="0">...</div></div>

Via JavaScript

Enable tabbable tabs via JavaScript (each tab needs to be activated individually):

consttriggerTabList=document.querySelectorAll('#myTab button')triggerTabList.forEach(triggerEl=>{consttabTrigger=newcoreui.Tab(triggerEl)triggerEl.addEventListener('click',event=>{event.preventDefault()tabTrigger.show()})})

You can activate individual tabs in several ways:

consttriggerEl=document.querySelector('#myTab button[data-coreui-target="#profile"]')coreui.Tab.getInstance(triggerEl).show()// Select tab by nameconsttriggerFirstTabEl=document.querySelector('#myTab li:first-child button')coreui.Tab.getInstance(triggerFirstTabEl).show()// Select first tab

Fade effect

To make tabs fade in, add.fade to each.tab-pane. The first tab pane must also have.show to make the initial content visible.

<divclass="tab-content"><divclass="tab-pane fade show active"id="home"role="tabpanel"aria-labelledby="home-tab"tabindex="0">...</div><divclass="tab-pane fade"id="profile"role="tabpanel"aria-labelledby="profile-tab"tabindex="0">...</div><divclass="tab-pane fade"id="messages"role="tabpanel"aria-labelledby="messages-tab"tabindex="0">...</div><divclass="tab-pane fade"id="settings"role="tabpanel"aria-labelledby="settings-tab"tabindex="0">...</div></div>

Methods

Asynchronous methods and transitions

All our API methods areasynchronous and initiate atransition. They return to the caller as soon as the transition begins butbefore it concludes. Furthermore, a method call on atransitioning component will be ignored.

Refer to our JavaScript documentation for further details.

constructor

You can create a tab instance with the constructor, for example:

constcuiTab=newcoreui.Tab('#myTab')
MethodDescription
disposeDestroys an element’s tab.
getInstanceStatic method which allows you to get the tab instance associated with a DOM element, you can use it like this:coreui.Tab.getInstance(element).
getOrCreateInstanceStatic method which allows you to get the tab instance associated with a DOM element, or create a new one in case it wasn’t initialized You can use it like this:coreui.Tab.getOrCreateInstance(element).
showSelects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden.Returns to the caller before the tab pane has actually been shown (i.e. before theshown.coreui.tab event occurs).

Events

When showing a new tab, the events fire in the following order:

  1. hide.coreui.tab (on the current active tab)
  2. show.coreui.tab (on the to-be-shown tab)
  3. hidden.coreui.tab (on the previous active tab, the same one as for thehide.coreui.tab event)
  4. shown.coreui.tab (on the newly-active just-shown tab, the same one as for theshow.coreui.tab event)

If no tab was already active, then thehide.coreui.tab andhidden.coreui.tab events will not be fired.

Event typeDescription
hide.coreui.tabThis event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Useevent.target andevent.relatedTarget to target the current active tab and the new soon-to-be-active tab, respectively.
hidden.coreui.tabThis event fires after a new tab is shown (and thus the previous active tab is hidden). Useevent.target andevent.relatedTarget to target the previous active tab and the new active tab, respectively.
show.coreui.tabThis event fires on tab show, but before the new tab has been shown. Useevent.target andevent.relatedTarget to target the active tab and the previous active tab (if available) respectively.
shown.coreui.tabThis event fires on tab show after a tab has been shown. Useevent.target andevent.relatedTarget to target the active tab and the previous active tab (if available) respectively.
consttabEl=document.querySelector('button[data-coreui-toggle="tab"]')tabEl.addEventListener('shown.coreui.tab',event=>{event.target// newly activated tabevent.relatedTarget// previous active tab})

Customizing

CSS variables

Navs use local CSS variables on.nav,.nav-tabs,.nav-pills,.nav-underline and.nav-underline-border for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.

On the.nav base class:

scss/_nav.scss
--cui-nav-link-padding-x:#{$nav-link-padding-x};--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:#{$nav-link-color};--cui-nav-link-hover-color:#{$nav-link-hover-color};--cui-nav-link-disabled-color:#{$nav-link-disabled-color};

On the.nav-tabs modifier class:

scss/_nav.scss
--cui-nav-tabs-border-width:#{$nav-tabs-border-width};--cui-nav-tabs-border-color:#{$nav-tabs-border-color};--cui-nav-tabs-border-radius:#{$nav-tabs-border-radius};--cui-nav-tabs-link-hover-border-color:#{$nav-tabs-link-hover-border-color};--cui-nav-tabs-link-active-color:#{$nav-tabs-link-active-color};--cui-nav-tabs-link-active-bg:#{$nav-tabs-link-active-bg};--cui-nav-tabs-link-active-border-color:#{$nav-tabs-link-active-border-color};

On the.nav-pills modifier class:

scss/_nav.scss
--cui-nav-pills-border-radius:#{$nav-pills-border-radius};--cui-nav-pills-link-active-color:#{$nav-pills-link-active-color};--cui-nav-pills-link-active-bg:#{$nav-pills-link-active-bg};
Added in v5.0.0

On the.nav-underline modifier class:

scss/_nav.scss
--cui-nav-underline-gap:#{$nav-underline-gap};--cui-nav-underline-border-width:#{$nav-underline-border-width};--cui-nav-underline-link-active-color:#{$nav-underline-link-active-color};
Added in v5.0.0

On the.nav-underline-border modifier class:

scss/_nav.scss
--cui-nav-underline-border-gap:#{$nav-underline-border-gap};--cui-nav-underline-border-border-color:#{$nav-underline-border-border-color};--cui-nav-underline-border-border-width:#{$nav-underline-border-border-width};--cui-nav-underline-border-link-padding-x:#{$nav-underline-border-link-padding-x};--cui-nav-underline-border-link-padding-y:#{$nav-underline-border-link-padding-y};--cui-nav-underline-border-link-color:#{$nav-underline-border-link-color};--cui-nav-underline-border-link-active-color:#{$nav-underline-border-link-active-color};--cui-nav-underline-border-link-disabled-color:#{$nav-underline-border-link-disabled-color};

SASS variables

scss/_variables.scss
$nav-link-padding-y:.5rem;$nav-link-padding-x:1rem;$nav-link-font-size:null;$nav-link-font-weight:null;$nav-link-color:var(--#{$prefix}link-color);$nav-link-hover-color:var(--#{$prefix}link-hover-color);$nav-link-transition:color.15sease-in-out,background-color.15sease-in-out,border-color.15sease-in-out;$nav-link-disabled-color:var(--#{$prefix}secondary-color);$nav-link-focus-box-shadow:$focus-ring-box-shadow;$nav-tabs-border-color:var(--#{$prefix}border-color);$nav-tabs-border-width:var(--#{$prefix}border-width);$nav-tabs-border-radius:var(--#{$prefix}border-radius);$nav-tabs-link-hover-border-color:var(--#{$prefix}secondary-bg)var(--#{$prefix}secondary-bg)$nav-tabs-border-color;$nav-tabs-link-active-color:var(--#{$prefix}emphasis-color);$nav-tabs-link-active-bg:var(--#{$prefix}body-bg);$nav-tabs-link-active-border-color:var(--#{$prefix}border-color)var(--#{$prefix}border-color)$nav-tabs-link-active-bg;$nav-pills-border-radius:var(--#{$prefix}border-radius);$nav-pills-link-active-color:$component-active-color;$nav-pills-link-active-bg:$component-active-bg;$nav-underline-gap:1rem;$nav-underline-border-width:.125rem;$nav-underline-link-active-color:var(--#{$prefix}emphasis-color);$nav-underline-border-gap:.5rem;$nav-underline-border-border-color:var(--#{$prefix}border-color);$nav-underline-border-border-width:.125rem;$nav-underline-border-link-padding-y:.5rem;$nav-underline-border-link-padding-x:.5rem;$nav-underline-border-link-color:var(--#{$prefix}secondary-color);$nav-underline-border-link-active-color:var(--#{$prefix}primary);$nav-underline-border-link-disabled-color:var(--#{$prefix}tertiary-color);$nav-enclosed-padding:.125rem;$nav-enclosed-bg:var(--#{$prefix}tertiary-bg);$nav-enclosed-border-radius:$border-radius-lg;$nav-enclosed-link-padding-y:.375rem;$nav-enclosed-link-padding-x:.875rem;$nav-enclosed-link-color:var(--#{$prefix}body-color);$nav-enclosed-link-border-width:1px;$nav-enclosed-link-active-color:var(--#{$prefix}body-color);$nav-enclosed-link-active-bg:var(--#{$prefix}body-bg);$nav-enclosed-link-active-border-color:var(--#{$prefix}border-color);$nav-enclosed-link-hover-box-shadow:var(--#{$prefix}box-shadow-sm);$nav-enclosed-link-disabled-color:var(--#{$prefix}secondary-color);

CoreUI vs Bootstrap

While this Nav component is fully compatible with Bootstrap and follows its core principles, CoreUI delivers a more complete solution for modern app development.

What sets CoreUI apart from Bootstrap?

  • Fully compatible with Bootstrap – Built directly on Bootstrap, all classes and behaviors work as expected.
  • 🧠Framework-native versions – CoreUI provides dedicated libraries forReact.js,Vue.js, andAngular, unlike Bootstrap which relies on third-party plugins for JavaScript frameworks.
  • 👨‍💻Maintained by a full-time team – CoreUI is developed as a professional product, not a volunteer-driven project.
  • 📦More built-in components – Includes additional ready-to-use components like range sliders, multi-selects, steppers, etc.
  • 🛠️Sass Modules support today – CoreUI already supports Sass Modules, which are planned for Bootstrap 6.
  • 🌍Better LTR/RTL support – Uses modern CSS logical properties for seamless bidirectional layout support.
  • 🔒LTS (Long-Term Support) – Bootstrap now offers LTS only via paid third parties like HeroDevs, while CoreUI continues to offer long-term support natively and for free.

Whether you’re building internal tools, dashboards, or SaaS platforms — CoreUI combines the familiarity of Bootstrap with a more powerful, scalable, and production-ready ecosystem.

👉Explore CoreUI Bootstrap Components
👉Compare CoreUI vs Bootstrap


[8]ページ先頭

©2009-2025 Movatter.jp