Tabs

Introduction

The tabs structure consists of an unordered list of tabs that have hashes corresponding to tab ids. Then when you click on each tab, only the container with the corresponding tab id will become visible. You can add the class .disabled to make a tab inaccessible.

Variable Width Tabs

Default. Tabs automatically become scrollable if necessary.

Test 1 tab

Test 2 tab

Test 3 tab

Test 4 tab


Fixed Width Tabs

Add the .tabs-fixed-width class.

Test 1 tab

Test 2 tab

Test 3 tab

Test 4 tab

Test 5 tab

Tabs HTML Structure


  <!-- Default -->
  <div class="row">
      <ul class="tabs">
        <li class="tab"><a href="#test1">Test 1</a></li>
        <li class="tab"><a href="#test2">Test 2</a></li>
        <li class="tab disabled"><a href="#test3">Disabled Tab</a></li>
        <li class="tab"><a href="#test4">Test 4</a></li>
      </ul>
    <div id="test1" class="col s12"><p>Test 1 tab</p></div>
    <div id="test2" class="col s12"><p>Test 2 tab</p></div>
    <div id="test3" class="col s12"><p>Test 3 tab</p></div>
    <div id="test4" class="col s12"><p>Test 4 tab</p></div>
  </div>
  
  <!-- Fixed Width -->
  <div class="row">
      <ul class="tabs">
        <li class="tab"><a href="#testb1">Test 1</a></li>
        <li class="tab"><a href="#testb2">Test 2</a></li>
        <li class="tab"><a href="#testb3" class="active">Test 3</a></li>
        <li class="tab"><a href="#testb4">Test 4</a></li>
		<li class="tab"><a href="#testb5">Test 5</a></li>
      </ul>
    <div id="testb1" class="col s12"><p>Test 1 tab</p></div>
    <div id="testb2" class="col s12"><p>Test 2 tab</p></div>
    <div id="testb3" class="col s12"><p>Test 3 tab</p></div>
    <div id="testb4" class="col s12"><p>Test 4 tab</p></div>
	<div id="testb5" class="col s12"><p>Test 5 tab</p></div>
  </div>
        

Preselecting a tab

By default, the first tab is selected. But if this is not what you want, you can preselect a tab by either passing in the hash in the url ex:#test2. Or you can add the class active to the a tag.


  <li class="tab col s2"><a class="active" href="#test3">Test 3</a></li>
        

jQuery Plugin Initialization

Tabs are initialized automatically, but if you add tabs dynamically you will have to initialize them like this.


  $(document).ready(function(){
    $('ul.tabs').tabs();
  });
        

jQuery Plugin Methods

You can programmatically trigger a tab change with our select_tab method. You have to input the id of the tab you want to switch to. In the case of our demo it would be either test1, test2, test3, or test4.


  $(document).ready(function(){
    $('ul.tabs').tabs('select_tab', 'tab_id');
  });
        

jQuery Plugin Options

Option Name Description
onShow Execute a callback function when the tab is changed.
The callback provides a parameter which refers to the current tab being shown.
swipeable Set to true to enable swipeable tabs. This also uses the responsiveThreshold option. Default: false
responsiveThreshold The maximum width of the screen, in pixels, where the swipeable functionality initializes. Default: Infinity

Swipeable Tabs

By setting the swipeable option to true, you can enable tabs where you can swipe on touch enabled devices to switch tabs. Make sure you keep the tab content divs in the same wrapping container. You can also set the responsiveThreshold option to a screen width in pixels where the swipeable functionality will activate.

Note: This is also touch compatible! Try swiping with your finger to scroll through the carousel.

Test 1 tab

Test 2 tab

Test 3 tab


  <div class="row">
	<ul id="tabs-swipe-demo" class="tabs z-depth-1 lime lighten-5" style="z-index:2;">
	  <li class="tab"><a href="#test-swipe-1">Test 1</a></li>
	  <li class="tab"><a href="#test-swipe-2">Test 2</a></li>
	  <li class="tab"><a href="#test-swipe-3">Test 3</a></li>
	</ul>
	<div id="test-swipe-1" class="col s12 lime lighten-3"><p>Test 1 tab</p></div>
	<div id="test-swipe-2" class="col s12 lime lighten-2"><p>Test 2 tab</p></div>
	<div id="test-swipe-3" class="col s12 lime lighten-1"><p>Test 3 tab</p></div>
  </div>
        

For more detailed informations please visit: http://materializecss.com/tabs.html