Create a tabbed navigation with different styles.
The Tab component consists of clickable tabs, that are aligned side by side in a list. Its JavaScript functionality extends the Switcher component and is necessary to dynamically transition through different contents using the tabbed navigation.
Class/Attribute | Description |
---|---|
uk-tab |
Add this attribute to a <ul> element to define the Tab component. Use <a> elements as tab items within the list. |
.uk-active |
Add this class to a list item to apply an active state. |
.uk-disabled |
Add this class to a list item to apply a disabled state. Also remove the href attribute from the anchor to make it inaccessible through keyboard navigation. |
<ul uk-tab>
<li class="uk-active"><a href=""></a></li>
<li><a href=""></a></li>
<li class="uk-disabled"><a></a></li>
</ul>
<ul uk-tab>
<li class="uk-active"><a href="#">Left</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li class="uk-disabled"><a>Disabled</a></li>
</ul>
Add the .uk-tab-bottom
class to flip tab items to the bottom.
<ul class="uk-tab-bottom" uk-tab>…</ul>
<ul class="uk-tab-bottom" uk-tab>
<li class="uk-active"><a href="#">Left</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
</ul>
Add the .uk-tab-left
or .uk-tab-right
class to align tabs vertically to the left or right side. To save space, the alignment automatically switches back to horizontal when the viewport width goes below 960px.
When using the vertical alignment, you will usually create a grid to apply the layout as seen in the Switcher example.
<ul class="uk-tab-left" uk-tab>…</ul>
<ul class="uk-tab-right" uk-tab>…</ul>
<div class="uk-child-width-1-2@s" uk-grid>
<div>
<ul class="uk-tab-left" uk-tab>
<li class="uk-active"><a href="#">Left</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
<div>
<ul class="uk-tab-right" uk-tab>
<li class="uk-active"><a href="#">Right</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
</div>
To change the default breakpoint between the vertical and horizontal alignment, just apply the media
option to the attribute with the appropriate viewport width. Add a number in pixel, for example media: 640
, or a breakpoint, for example media: @m
.
<ul class="uk-tab-left" uk-tab="media: @s">…</ul>
You can combine tabs with the Flex component or the Width component to modify the alignment of the navigations.
<ul class="uk-flex-right" uk-tab>…</ul>
<div class="uk-margin-medium-top">
<ul class="uk-flex-center" uk-tab>
<li class="uk-active"><a href="#">Center</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
<div>
<ul class="uk-flex-right" uk-tab>
<li class="uk-active"><a href="#">Right</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
<div>
<ul class="uk-child-width-expand" uk-tab>
<li class="uk-active"><a href="#">Justify</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
Tabs can be used to trigger a dropdown menu from the Dropdown component.
<ul uk-tab>
<li>
<!-- This is the menu item toggling the dropdown -->
<a href=""></a>
<!-- This is the dropdown -->
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-dropdown-nav">…</ul>
</div>
</li>
</ul>
<ul uk-tab>
<li class="uk-active"><a href="#">Active</a></li>
<li><a href="#">Item</a></li>
<li>
<a href>More <span uk-icon="icon: triangle-down"></span></a>
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-dropdown-nav">
<li class="uk-active"><a href="#">Active</a></li>
<li><a href="#">Item</a></li>
<li class="uk-nav-header">Header</li>
<li><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li class="uk-nav-divider"></li>
<li><a href="#">Item</a></li>
</ul>
</div>
</li>
</ul>
Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more
Option | Value | Default | Description |
---|---|---|---|
connect |
CSS selector | false |
Related item's container. By default, this is the next element with the 'uk-switcher' class. |
toggle |
CSS selector | > * |
The toggle selector, which triggers content switching on click. |
active |
Number | 0 |
Active index on init. Providing a negative number indicates a position starting from the end of the set. |
animation |
String | false |
Space-separated names of animations. Comma-separated for animation out. |
duration |
Number | 200 |
The animation duration. |
swiping |
Boolean | true |
Use swiping. |
media |
Number, String | 960 |
When to switch to horizontal mode - a width as integer (e.g. 640) or a breakpoint (e.g. @s, @m, @l, @xl) or any valid media query (e.g. (min-width: 900px)). |
Learn more about JavaScript components.
UIkit.tab(element, options);
The following events will be triggered on the connected items of the elements with this component attached:
Name | Description |
---|---|
beforeshow |
Fires before an item is shown. Can prevent showing by calling preventDefault() on the event. |
show |
Fires after an item is shown. |
shown |
Fires after the item's show animation has been completed. |
beforehide |
Fires before an item is hidden. Can prevent hiding by calling preventDefault() on the event. |
hide |
Fires after an item's hide animation has started. |
hidden |
Fires after an item is hidden. |
The following methods are available for the component:
UIkit.tab(element).show(index);
Shows the Tab item with the given index.
Name | Type | Default | Description |
---|---|---|---|
index |
String, Number, Node | 0 | Tab item to show. 0 based index. |
The Tab component adheres to the Tab WAI-ARIA design pattern and automatically sets the appropriate WAI-ARIA roles, states and properties.
tablist
role, and if it is a Nav component, the aria-orientation
state is set to vertical
. presentation
role. tab
role, the aria-selected
state and the aria-controls
property set to the ID of the respective content item. presentation
role.tabpanel
role and the aria-labelledby
property set to the ID of the respective tab.The tab navigation can be accessed through the keyboard using the following keys.
By default, the Switcher component has the manual activation behavior. This means the corresponding content items will only be activated using the enter or spacekeys. To switch to automatic activation, set follow-focus
to true
. When navigating through tab items, the corresponding content item will get active automatically.