Skip to content

Material Tabs

A material design styled tabs component that provides a tabbed interface with smooth animations and a sliding indicator.

This component has no additional dependencies beyond the core Metro UI library.

<ul data-role="materialtabs">
<li><a href="#tab1">Tab 1</a></li>
<li class="active"><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div id="tab1">Content for Tab 1</div>
<div id="tab2">Content for Tab 2</div>
<div id="tab3">Content for Tab 3</div>

Fixed tabs distribute evenly across the available width.

<ul data-role="materialtabs" data-fixed-tabs="true">
<li><a href="#tab1">Tab 1</a></li>
<li class="active"><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<ul data-role="materialtabs" data-app-bar="true">
<li><a href="#tab1">Tab 1</a></li>
<li class="active"><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<ul data-role="materialtabs" data-deep="true">
<li><a href="#tab1">Tab 1</a></li>
<li class="active"><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
ParameterTypeDefaultDescription
wheelStepnumber20The number of pixels to scroll when using the mouse wheel
materialTabsDeferrednumber0Delay in milliseconds before initialization
deepbooleanfalseWhen true, sets a lower z-index for the tabs
fixedTabsbooleanfalseWhen true, tabs are distributed evenly across the available width
durationnumber300Animation duration in milliseconds
appBarboolean|stringfalseIndicates if an app bar is present. Use “more” for additional spacing
clsComponentstring""Additional CSS class for the component wrapper
clsTabsstring""Additional CSS class for the tabs container
clsTabstring""Additional CSS class for each tab
clsTabActivestring""Additional CSS class for the active tab
clsMarkerstring""Additional CSS class for the tab marker
  • open(tab_num) - Opens the tab at the specified index (1-based).
const tabs = Metro.getPlugin('#my-tabs', 'material-tabs');
tabs.open(2); // Opens the second tab
  • openTab(tab_to_open, tab_next) - Opens the specified tab element.
const tabs = Metro.getPlugin('#my-tabs', 'material-tabs');
const tabElement = document.querySelector('#my-tabs li:nth-child(2)');
tabs.openTab(tabElement, true);
EventDescription
onBeforeTabOpenTriggered before a tab is opened. Return false to prevent the tab from opening.
onTabOpenTriggered after a tab is opened.
onTabsScrollTriggered when the tabs are scrolled.
onTabsCreateTriggered when the tabs component is created.
VariableDefault (Light)Dark ModeDescription
--tabs-material-background#ffffff#343637Controls the background color of the tabs
--tabs-material-color#191919#dbdfe7Controls the text color of the tabs
--tabs-material-marker-color#000000#ff6211Controls the color of the active tab marker
#my-tabs {
--tabs-material-background: #f5f5f5;
--tabs-material-color: #424242;
--tabs-material-marker-color: #2196F3;
}
  • .tabs-material-wrapper - The wrapper for the tabs component
  • .tabs-material - The main container class for the tabs
  • .deep - Lowers the z-index of the tabs
  • .fixed-tabs - Makes tabs distribute evenly across the available width
  • .with-icons - Adjusts the height for tabs with icons
  • .app-bar-present - Adjusts positioning when an app bar is present
  • .app-bar-present-more - Adjusts positioning when an app bar with more content is present
  • .tab-marker - The sliding indicator that shows the active tab
  • .tab-badge - Used for badges within tabs