Switcher

Dynamically transition through different content panes.

Usage

The Switcher component consists of a number of toggles and their related content items. Add the data-uk-switcher attribute to a list element which contains the toggles. Add the .uk-switcher class to the element containing the content items.

By default, the element with the .uk-switcher class has to succeed the toggle directly in order for the switcher to function. If you need it to be nested in another element, for example when using a grid, add the connect: SELECTOR option to the data-uk-switcher attribute and select the element containing the items for switching.

Typically, the switcher toggles are styled through other components, some of which will be shown here.

<!-- This is the nav containing the toggling elements -->
<ul data-uk-switcher>
<li><a href="#"></a></li>
</ul>
<!-- This is the container of the content items -->
<ul class="uk-switcher">
<li></li>
</ul>

In this example we are using the Subnav component.

    • Hello!
    • Hello again!
    • Bazinga!
  • Something's not working? Feel free to report an issue or edit this snippet .

    <ul class="uk-subnav uk-subnav-primary" uk-switcher>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul class="uk-switcher mt-4">
    <li>Hello!</li>
    <li>Hello again!</li>
    <li>Bazinga!</li>
    </ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div>
    <ul className="uk-subnav uk-subnav-primary" uk-switcher>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul className="uk-switcher mt-4">
    <li>Hello!</li>
    <li>Hello again!</li>
    <li>Bazinga!</li>
    </ul>
    </div>

In some cases you want to switch to another content section from within the active content. This is possible using the data-uk-switcher-item attribute. To target the items, you need to set the attribute to the number of the respective content item.

Setting the attribute to next and previous will switch to the adjacent items.

<ul class="uk-switcher mt-4">
<li><a href="#" data-uk-switcher-item="0"></a></li>
<li><a href="#" data-uk-switcher-item="1"></a></li>
<li><a href="#" data-uk-switcher-item="next"></a></li>
<li><a href="#" data-uk-switcher-item="previous"></a></li>
</ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <ul class="uk-subnav uk-subnav-primary" uk-switcher>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul class="uk-switcher mt-4">
    <li>
    Hello! <a class="uk-link" href="#" uk-switcher-item="2">Switch to item 3</a>
    </li>
    <li>
    Hello again!
    <a class="uk-link" href="#" uk-switcher-item="next">Next item</a>
    </li>
    <li>
    Bazinga!
    <a class="uk-link" href="#" uk-switcher-item="previous">Previous item</a>
    </li>
    </ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div>
    <ul className="uk-subnav uk-subnav-primary" uk-switcher>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul className="uk-switcher mt-4">
    <li>
    Hello! <a className="uk-link" href="#" uk-switcher-item={2}>Switch to item 3</a>
    </li>
    <li>
    Hello again!
    <a className="uk-link" href="#" uk-switcher-item="next">Next item</a>
    </li>
    <li>
    Bazinga!
    <a className="uk-link" href="#" uk-switcher-item="previous">Previous item</a>
    </li>
    </ul>
    </div>

Connect multiple containers

It is also possible to connect multiple content containers. Just add the connect parameter to the data-uk-switcher attribute and use a selector that applies to all items.

<!-- This is the nav containing the toggling elements -->
<ul data-uk-switcher="connect: .my-class">
...
</ul>
<!-- These are the containers of the content items -->
<ul class="my-class uk-switcher">
...
</ul>
<ul class="my-class uk-switcher">
...
</ul>
  • Container 1

    • Hello!
    • Hello again!
    • Bazinga!

    Container 2

    • Hello! The first item.
    • Hello again! The second item.
    • Bazinga! The third item.
  • Something's not working? Feel free to report an issue or edit this snippet .

    <ul
    class="uk-subnav uk-subnav-primary"
    data-uk-switcher="connect: .switcher-container"
    >
    <li><a href="#">Active</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <h4 class="mt-4">Container 1</h4>
    <ul class="switcher-container uk-switcher mt-4">
    <li>Hello!</li>
    <li>Hello again!</li>
    <li>Bazinga!</li>
    </ul>
    <h4 class="mt-4">Container 2</h4>
    <ul class="switcher-container uk-switcher mt-4">
    <li>Hello! The first item.</li>
    <li>Hello again! The second item.</li>
    <li>Bazinga! The third item.</li>
    </ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div>
    <ul className="uk-subnav uk-subnav-primary" data-uk-switcher="connect: .switcher-container">
    <li><a href="#">Active</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <h4 className="mt-4">Container 1</h4>
    <ul className="switcher-container uk-switcher mt-4">
    <li>Hello!</li>
    <li>Hello again!</li>
    <li>Bazinga!</li>
    </ul>
    <h4 className="mt-4">Container 2</h4>
    <ul className="switcher-container uk-switcher mt-4">
    <li>Hello! The first item.</li>
    <li>Hello again! The second item.</li>
    <li>Bazinga! The third item.</li>
    </ul>
    </div>

Animations

You can apply all animations from the Animation component to switcher items. To do so, add the animation parameter with the relevant class to the data-uk-switcher attribute.

<ul data-uk-switcher="animation: uk-anmt-fade">
...
</ul>
    • Hello!
    • Hello again!
    • Bazinga!
  • Something's not working? Feel free to report an issue or edit this snippet .

    <ul
    class="uk-subnav uk-subnav-primary"
    data-uk-switcher="animation: uk-anmt-fade"
    >
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul class="uk-switcher mt-4">
    <li>Hello!</li>
    <li>Hello again!</li>
    <li>Bazinga!</li>
    </ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div>
    <ul className="uk-subnav uk-subnav-primary" data-uk-switcher="animation: uk-anmt-fade">
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul className="uk-switcher mt-4">
    <li>Hello!</li>
    <li>Hello again!</li>
    <li>Bazinga!</li>
    </ul>
    </div>

Multiple animations

You can also apply multiple animations from the Animation component. That way you can add different in and out animations.

<ul data-uk-switcher="animation: uk-anmt-slide-left-md, uk-anmt-slide-right-md">
...
</ul>
    • Hello!
    • Hello again!
    • Bazinga!
  • Something's not working? Feel free to report an issue or edit this snippet .

    <ul
    class="uk-subnav uk-subnav-primary"
    data-uk-switcher="animation: uk-anmt-slide-left-md, uk-anmt-slide-right-md"
    >
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul class="uk-switcher mt-4">
    <li>Hello!</li>
    <li>Hello again!</li>
    <li>Bazinga!</li>
    </ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div>
    <ul className="uk-subnav uk-subnav-primary" data-uk-switcher="animation: uk-anmt-slide-left-md, uk-anmt-slide-right-md">
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul className="uk-switcher mt-4">
    <li>Hello!</li>
    <li>Hello again!</li>
    <li>Bazinga!</li>
    </ul>
    </div>

Switcher and subnav

The switcher is easily applied to the Subnav component.

<!-- This is the subnav containing the toggling elements -->
<ul class="uk-subnav uk-subnav-primary" uk-switcher>
...
</ul>
<!-- This is the container of the content items -->
<ul class="uk-switcher"></ul>
    • Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    • Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    • Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
  • Something's not working? Feel free to report an issue or edit this snippet .

    <ul class="uk-subnav uk-subnav-primary" uk-switcher>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul class="uk-switcher mt-4">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
    aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
    eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div>
    <ul className="uk-subnav uk-subnav-primary" uk-switcher>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    <ul className="uk-switcher mt-4">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
    aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
    eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>

Switcher and tab

As an exception to the rule, add the data-uk-tab attribute instead of data-uk-switcher to the tabbed navigation to combine the switcher with the Tab component.

<!-- This is the subnav containing the toggling elements -->
<ul data-uk-tab>
...
</ul>
<!-- This is the container of the content items -->
<ul class="uk-switcher">
...
</ul>
    • Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    • Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    • Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
  • Something's not working? Feel free to report an issue or edit this snippet .

    <ul data-uk-tab>
    <li><a class="px-4 pb-3 pt-2" href="#">Item</a></li>
    <li><a class="px-4 pb-3 pt-2" href="#">Item</a></li>
    <li><a class="px-4 pb-3 pt-2" href="#">Item</a></li>
    </ul>
    <ul class="uk-switcher mt-4">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
    aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
    eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div>
    <ul data-uk-tab>
    <li><a className="px-4 pb-3 pt-2" href="#">Item</a></li>
    <li><a className="px-4 pb-3 pt-2" href="#">Item</a></li>
    <li><a className="px-4 pb-3 pt-2" href="#">Item</a></li>
    </ul>
    <ul className="uk-switcher mt-4">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
    aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
    eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>

Vertical tabs

You can use the width and grid utility classes from Tailwind CSS to display content correctly with a vertical tabbed navigation.

<div uk-grid>
<div class="uk-width-auto">
<ul class="uk-tab-left" data-uk-tab="connect: #my-id">
...
</ul>
</div>
<div class="uk-width-expand">
<ul id="my-id" class="uk-switcher">
...
</ul>
</div>
</div>
    • Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    • Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    • Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
    • Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    • Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    • Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div class="grid grid-cols-1 gap-4 lg:grid-cols-2">
    <div>
    <div class="flex flex-col gap-4 lg:flex-row">
    <div class="flex-none">
    <ul
    class="uk-tab-left"
    data-uk-tab="connect: #component-tab-left; animation: uk-anmt-fade"
    >
    <li><a href="#">Active</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    </div>
    <div class="flex-1">
    <ul id="component-tab-left" class="uk-switcher">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
    eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
    nisi ut aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>
    </div>
    </div>
    <div>
    <div class="flex flex-col gap-4 lg:flex-row">
    <div class="flex-none lg:order-last">
    <ul
    class="uk-tab-right"
    data-uk-tab="connect: #component-tab-right; animation: uk-anmt-fade"
    >
    <li><a href="#">Active</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    </div>
    <div class="flex-1">
    <ul id="component-tab-right" class="uk-switcher">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
    eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
    nisi ut aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>
    </div>
    </div>
    </div>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
    <div>
    <div className="flex flex-col gap-4 lg:flex-row">
    <div className="flex-none">
    <ul className="uk-tab-left" data-uk-tab="connect: #component-tab-left; animation: uk-anmt-fade">
    <li><a href="#">Active</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    </div>
    <div className="flex-1">
    <ul id="component-tab-left" className="uk-switcher">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
    eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
    nisi ut aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>
    </div>
    </div>
    <div>
    <div className="flex flex-col gap-4 lg:flex-row">
    <div className="flex-none lg:order-last">
    <ul className="uk-tab-right" data-uk-tab="connect: #component-tab-right; animation: uk-anmt-fade">
    <li><a href="#">Active</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    </div>
    <div className="flex-1">
    <ul id="component-tab-right" className="uk-switcher">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
    eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
    nisi ut aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>
    </div>
    </div>
    </div>

Switcher and button

The switcher can also be applied to buttons or button groups from the Button component. Just add the switcher attribute to a block around a group of buttons or to the element with the .uk-btn-group class.

<!-- This is a switcher using a number of buttons -->
<div data-uk-switcher="toggle: > *">
<button class="uk-btn uk-btn-default" type="button"></button>
<button class="uk-btn uk-btn-default" type="button"></button>
</div>
<ul class="uk-switcher">
...
</ul>
    • Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    • Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    • Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div
    class="flex flex-wrap gap-2"
    data-uk-switcher="animation: uk-anmt-fade; toggle: > *"
    >
    <button class="uk-btn uk-btn-primary" type="button">Item</button>
    <button class="uk-btn uk-btn-primary" type="button">Item</button>
    <button class="uk-btn uk-btn-primary" type="button">Item</button>
    </div>
    <ul class="uk-switcher mt-4">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
    aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
    eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div>
    <div className="flex flex-wrap gap-2" data-uk-switcher="animation: uk-anmt-fade; toggle: > *">
    <button className="uk-btn uk-btn-primary" type="button">Item</button>
    <button className="uk-btn uk-btn-primary" type="button">Item</button>
    <button className="uk-btn uk-btn-primary" type="button">Item</button>
    </div>
    <ul className="uk-switcher mt-4">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
    aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
    eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>

Note Since this example does not wrap the buttons into list items the clickable elements which trigger the content switching has to be changed by using the toggle option.

Switcher and nav

To apply the switcher to the Nav component, add the data-uk-switcher attribute to the nav <ul> element. Use the Grid and Width components to arrange nav and content in a grid layout.

<div class="flex">
<div class="w-1/4">
<ul class="uk-nav uk-nav-default" data-uk-switcher="connect: #my-id">
...
</ul>
</div>
<div class="flex-1">
<ul id="my-id" class="uk-switcher">
...
</ul>
</div>
</div>
    • Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    • Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    • Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur, sed do eiusmod.
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div class="flex">
    <div class="w-40">
    <ul
    class="uk-nav uk-nav-default"
    data-uk-switcher="connect: #component-nav; animation: uk-anmt-fade"
    >
    <li><a href="#">Active</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    </div>
    <div class="flex-1">
    <ul id="component-nav" class="uk-switcher">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
    ut aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
    dolore eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>
    </div>
  • Something's not working? Feel free to report an issue or edit this snippet .

    <div className="flex">
    <div className="w-40">
    <ul className="uk-nav uk-nav-default" data-uk-switcher="connect: #component-nav; animation: uk-anmt-fade">
    <li><a href="#">Active</a></li>
    <li><a href="#">Item</a></li>
    <li><a href="#">Item</a></li>
    </ul>
    </div>
    <div className="flex-1">
    <ul id="component-nav" className="uk-switcher">
    <li>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua.
    </li>
    <li>
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
    ut aliquip ex ea commodo consequat.
    </li>
    <li>
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
    dolore eu fugiat nulla pariatur, sed do eiusmod.
    </li>
    </ul>
    </div>
    </div>

Component options

Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more

OptionValueDefaultDescription
connectCSS selector~.uk-switcherRelated items container. By default succeeding elements with class ‘uk-switcher’.
toggle CSS selector> * > :first-childSelect the clickable elements which trigger content switching.
itemNav CSS selectorfalseRelated nav container. By default, nav items are found in related items container only.
active Number0Active index on init. Providing a negative number indicates a position starting from the end of the set.
animationStringfalseSpace-separated names of animations. Comma-separated for animation out.
durationNumber200The animation duration.
swipingBooleantrueUse swiping.
followFocusBooleanfalseSelection follows focus automatically.

connect is the Primary option and its key may be omitted, if it’s the only option in the attribute value.

<span data-uk-switcher=".switcher-container"></span>

JavaScript

Learn more about JavaScript components.

Initialization

UIkit.switcher(element, options);

Events

The following events will be triggered on the connected items of the elements with this component attached:

NameDescription
beforeshowFires before an item is shown. Can prevent showing by calling preventDefault() on the event.
showFires after an item is shown.
shownFires after the item’s show animation has completed.
beforehideFires before an item is hidden. Can prevent hiding by calling preventDefault() on the event.
hideFires after an item’s hide animation has started.
hiddenFires after an item is hidden.

Methods

The following methods are available for the component:

Show

UIkit.switcher(element).show(index);

Shows the Switcher item with given index.

NameTypeDefaultDescription
indexString, Number, Node0Switcher item to show. 0 based index.

Accessibility

The Switcher component adheres to the Tab WAI-ARIA design pattern and automatically sets the appropriate WAI-ARIA roles, states and properties.

  • The toggle navigation has the tablist role, and if it is a Nav component, the aria-orientation state set to vertical.
  • The toggle navigation items have the presentation role.
  • The toggle navigation links have an ID, the tab role, the aria-selected state and the aria-controls property set to the ID of the respective content item.
  • The content list has the presentation role.
  • The content list items have the ID, the tabpanel role and the aria-labelledby property set to the ID of the respective toggle item.

Keyboard interaction

The toggle navigation can be accessed through keyboard using the following keys.

  • The tab or shift+tab keys place focus on the active toggle in the toggle navigation. If the focus already is on the active toggle, the focus will move to the next element outside the toggle navigation.
  • The left/right arrow or up/down arrow keys, depending on the orientation, navigate through the toggles. If the focus is on the last toggle, it moves to the first toggle.
  • The enter or space keys activate the corresponding content item of the focused toggle.
  • The home or end keys move the focus to the first or last toggle.

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 toggle items, the corresponding content item will get active automatically.

Customize

Customize your Franken UI experience.