Skip to content

Tabs

The Tabs Component provides a way to organize content into multiple tabs, allowing users to switch between different sections of content within the same area of a page.

  • Metro UI Core
  • DOM Library
<ul data-role="tabs">
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div class="tabs-targets">
<div id="tab1">Content for Tab 1</div>
<div id="tab2">Content for Tab 2</div>
<div id="tab3">Content for Tab 3</div>
</div>
<ul data-role="tabs"
data-expand="true"
data-update-uri="true"
data-type="pills"
data-position="top"
data-align="center">
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>

You can link multiple tab components to synchronize their tab switching:

<ul id="tabs1" data-role="tabs" data-link="engine">
<li><a href="#npm_1">npm</a></li>
<li><a href="#pnpm_1">pnpm</a></li>
</ul>
<ul id="tabs2" data-role="tabs" data-link="engine">
<li><a href="#npm_2">npm</a></li>
<li><a href="#pnpm_2">pnpm</a></li>
</ul>
ParameterTypeDefaultDescription
tabsDeferredNumber0Deferred initialization time in milliseconds
expandBooleanfalseWhether to expand tabs in mobile view
expandPointStringnullMedia breakpoint at which tabs expand (e.g., “md”)
typeString”default”Tab style type: “default”, “text”, “group”, “pills”
updateUriBooleanfalseUpdate browser URL hash when switching tabs
positionString”top”Position of tabs: “top”, “bottom”, “left”, “right”
alignString”left”Alignment of tabs: “left”, “center”, “right”
linkString""Link tabs with the same link value to synchronize tab switching
clsTabsString""Additional CSS class for tabs container
clsTabsListString""Additional CSS class for tabs list
clsTabsListItemString""Additional CSS class for tabs list items
clsTabsListItemActiveString""Additional CSS class for active tabs list item

Move to the next tab.

const tabs = Metro.getPlugin('#myTabs', 'tabs');
tabs.next();

Move to the previous tab.

const tabs = Metro.getPlugin('#myTabs', 'tabs');
tabs.prev();

Open a specific tab. The tab parameter can be:

  • A number (starting from 1) to open a tab by index
  • A jQuery object representing the tab element
  • A DOM element representing the tab
const tabs = Metro.getPlugin('#myTabs', 'tabs');
tabs.open(1); // Open first tab
tabs.open($('#tab')); // Open tab by jQuery object

Open a tab by its target ID.

const tabs = Metro.getPlugin('#myTabs', 'tabs');
tabs.openByTarget('#tab1');

Open a tab by its zero-based index.

const tabs = Metro.getPlugin('#myTabs', 'tabs');
tabs.openByIndex(0); // Open first tab
EventDescription
onTabTriggered when a tab is clicked
onTabOpenTriggered when a tab is opened
onTabCloseTriggered when a tab is closed
onBeforeTabTriggered before a tab is opened (return false to prevent opening)
onTabsCreateTriggered when the tabs component is created
<ul data-role="tabs"
data-on-tab="console.log('tab clicked')"
data-on-tab-open="console.log('tab opened')"
data-on-tab-close="console.log('tab closed')">
<!-- tabs content -->
</ul>
VariableDefault (Light)Dark ModeDescription
--tabs-border-radius6px6pxBorder radius for tabs
--tabs-border-radius-pills16px16pxBorder radius for pills-style tabs
--tabs-backgroundvar(—default-background)var(—default-background)Background color for tabs container
--tabs-colorvar(—default-color)var(—default-color)Text color for tabs container
--tabs-hamburger-backgroundtransparenttransparentBackground color for hamburger menu in mobile view
--tabs-hamburger-color#000000#ffffffColor for hamburger menu in mobile view
--tabs-item-backgroundvar(—default-background)var(—default-background)Background color for tab items
--tabs-item-colorvar(—default-color)var(—default-color)Text color for tab items
--tabs-item-background-hover#f5f8fe#26282eBackground color for tab items on hover
--tabs-item-color-hovervar(—default-color)var(—default-color)Text color for tab items on hover
--tabs-item-background-active#eaeaea#4a4d51Background color for active tab items
--tabs-item-color-activevar(—default-color)var(—default-color)Text color for active tab items
--tabs-item-marker-active#2bcc19#4fff39Color for active tab marker
--tabs-item-icon-background#ffffff#343637Background color for tab item icons
--tabs-item-icon-color#000000#ffffffColor for tab item icons
.my-custom-tabs {
--tabs-border-radius: 10px;
--tabs-item-background-active: #007bff;
--tabs-item-color-active: #ffffff;
--tabs-item-marker-active: #ff9900;
}
  • .tabs - Main container class
  • .tabs-list - Class for the tabs list (ul element)
  • .tabs-targets - Container for tab content
  • .tabs-top - Tabs positioned at the top
  • .tabs-bottom - Tabs positioned at the bottom
  • .tabs-left - Tabs positioned at the left
  • .tabs-right - Tabs positioned at the right
  • .tabs-default - Default tabs style
  • .tabs-text - Text-only tabs style
  • .tabs-group - Group-style tabs
  • .tabs-pills - Pills-style tabs
  • .align-left - Align tabs to the left
  • .align-center - Align tabs to the center
  • .align-right - Align tabs to the right
  • .active - Active tab
  • .expand - Expanded tabs in mobile view
  • .tabs-expand - Container with expanded tabs