Tabs
Tabs lets you create content using an ul
list of links that are linked to an unique id
of a section
elements with each tab having its own content. Wrapping all of it is a div
with tabs
class.
Keyboard navigation
The user is able to select and activate tabs using the left and right arrow keys, while the Tab key is preserved for focusing contents within and below the active tab panel. Pressing Shift + Tab returns the user to the selected tab.
Section 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam euismod, tortor nec pharetra ultricies, ante erat imperdiet velit, nec laoreet enim lacus a velit. Nam luctus, enim in interdum condimentum, nisl diam iaculis lorem, vel volutpat mi leo sit amet lectus. Praesent non odio bibendum magna bibendum accumsan.
Section 2
Nullam at diam nec arcu suscipit auctor non a erat. Sed et magna semper, eleifend magna non, facilisis nisl. Proin et est et lorem dictum finibus ut nec turpis. Aenean nisi tortor, euismod a mauris a, mattis scelerisque tortor. Sed dolor risus, varius a nibh id, condimentum lacinia est. In lacinia cursus odio a aliquam. Curabitur tortor magna, laoreet ut rhoncus at, sodales consequat tellus.
Section 3
Phasellus ac tristique orci. Nulla maximus justo nec dignissim consequat. Sed vehicula diam sit amet mi efficitur vehicula in in nisl. Aliquam erat volutpat. Suspendisse lorem turpis, accumsan consequat consectetur gravida, pellentesque ac ante. Aliquam in commodo ligula, sit amet mollis neque. Vestibulum at facilisis massa.
Section 4
Nam luctus, enim in interdum condimentum, nisl diam iaculis lorem, vel volutpat mi leo sit amet lectus. Praesent non odio bibendum magna bibendum accumsan. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam euismod, tortor nec pharetra ultricies, ante erat imperdiet velit, nec laoreet enim lacus a velit.
Bootsrap Tabs
Bootstrap tabs component uses .nav-tabs
class and requires the .nav
base class. Tabs also uses HTML5 roles for accessibility.
Add role="tablist"
to the ul that contains the tab links,
and add role="tab"
to the anchor tag that is the tab link.
The tab link also requires an HTML5 data-toggle="tab"
attribute
be applied to instantiate the javascript behavior.
Responsive Tabs
Tabs on small mobile devices can be a really bad experience. By applying the .responsive
class to the .tab-group
element, the tab will transform from a tab list to an accordion list on small mobile devices. Following example is using bootstrap cards to display tabs as accordion list in mobile devices: