Tabs
Materialize is a modern responsive CSS framework based on Material Design by Google.
Tabs automatically become scrollable when there are too many to fit on screen
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Test 11
Initialization
var instance = M.Tabs.init(el, options);
Options
Name | Type | Default | Description |
---|---|---|---|
duration | Number | 300 | Transition duration in milliseconds. |
onShow | Function | null | Callback for when a new tab content is shown. |
swipeable | Boolean | false | Set to true to enable swipeable tabs. This also uses the responsiveThreshold option. |
responsiveThreshold | Number | Infinity | The maximum width of the screen, in pixels, where the swipeable functionality initializes. |
Methods
All the methods are called on the plugin instance. You can get the plugin instance like this:
var instance = M.Tabs.getInstance(elem);
.select();
Show tab content that corresponds to the tab with the id
Arguments
String: The id of the tab that you want to switch to
instance.select('tab_id');
.updateTabIndicator();
Recalculate tab indicator position. This is useful when the indicator position is not correct.
instance.updateTabIndicator();
.destroy();
Destroy plugin instance and teardown
instance.destroy();
Properties
Name | Type | Description |
---|---|---|
el | Element | The DOM element the plugin was initialized with. |
options | Object | The options the instance was initialized with. |
index | Number | The index of tab that is currently shown. |
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.
Test 3
Linking to an External Page
By default, Materialize tabs will ignore their default anchor behaviour. To force a tab to behave as a regular hyperlink, just specify the
target
property of that link! A list of target
values may be
found here.
External link in new window
External link in same window
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
Test 2
Test 3
Fixed Width Tabs
Add the
.tabs-fixed-width
class to the tabs container
Test 1
Test 2
Test 3
Test 4
Test 5
Test 1
Test 2
Test 3
Test 4
Test 5