Create a list of items to use as a responsive carousel slider

The slider is a responsive display of elements that can be scrolled through using the mouse or touch gestures.

Usage

To apply the Slider component, add the data-uk-slider attribute to a container element around a .uk-slider-container element. Add a list of items and assign the .uk-slider class to the list. Use the .uk-width-* and .uk-grid-width-* classes to determine how many elements are visible at once.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]
  • 11 [600x400]
  • 12 [600x400]

Markup

<div data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-4">
            <li>...</li>
            ...
        </ul>
    </div>

</div>

The slider itself can be scrolled with click and drag of the mouse or swiping on touch devices. It is a good idea to also add a clickable slidenav navigation. The slidenav adds arrows buttons that appear when you hover the slider.

Example

<div class="uk-slidenav-position" data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-4">
            <li>...</li>
            ...
        </ul>
    </div>

    <a href="" class="uk-slidenav uk-slidenav-contrast uk-slidenav-previous" data-uk-slider-item="previous"></a>
    <a href="" class="uk-slidenav uk-slidenav-contrast uk-slidenav-next" data-uk-slider-item="next"></a>

</div>

Center Mode

By default, elements of the slider always align to the left edge of the slider container. If you want to center the elements instead, set the center attribute to true.

Note The center list element always has the class .uk-active added. You can make use of that if you want to highlight the center element.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]
  • 11 [600x400]
  • 12 [600x400]

Markup

<div data-uk-slider="{center:true}">

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-4">
            <li>...</li>
            ...
        </ul>
    </div>


</div>

Disable Infinite Scrolling

By default, the slider loops through all items. To disable that behaviour, set the infinite parameter to false. This works both with center mode enabled and disabled.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 9 [600x400]
  • 10 [600x400]
  • 11 [600x400]
  • 12 [600x400]

Markup

<div data-uk-slider="{infinite: false}">

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-4">
            <li>...</li>
            ...
        </ul>
    </div>

</div>

Item gutter

If you want some spacing between your elements, add the .uk-grid class to the slider container. The elements will then be spaced according to the grid gutter.

Note You can use the modifiers uk-grid-medium and uk-grid-small to change the gutter.

Example

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]

Item width

To set the widths of your elements, use the width classes from the UIkit grid. Either use the uk-grid-width-* classes on the slider container or use individual widths per list item using the uk-width-* classes.

Example: Individual widths

  • 1 [400x200]
  • 2 [240x200]
  • 3 [480x200]
  • 4 [300x200]
  • 5 [400x200]
  • 6 [240x200]
  • 1 [400x200]
  • 2 [240x200]
  • 3 [480x200]
  • 4 [300x200]
  • 5 [400x200]
  • 6 [240x200]
  • 1 [400x200]
  • 2 [240x200]
  • 3 [480x200]
  • 4 [300x200]
  • 5 [400x200]
  • 6 [240x200]

Markup

<div data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider">
            <li class="uk-width-1-3">...</li>
            <li class="uk-width-1-5">...</li>
            <li class="uk-width-2-5">...</li>
            ...
        </ul>
    </div>

</div>

Responsive behaviour

To adapt to different viewports, you can use the responsive grid classes. In the following example, the slider displays four items on large viewports, three on medium and just one item on small ones.

Example: Responsive widths

  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]
  • 1 [600x400]
  • 2 [600x400]
  • 3 [600x400]
  • 4 [600x400]
  • 5 [600x400]
  • 6 [600x400]
  • 7 [600x400]
  • 8 [600x400]

Markup

<div data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider uk-grid-width-medium-1-3 uk-grid-width-large-1-4">
            <li>...</li>
            ...
        </ul>
    </div>

</div>

Fullscreen mode

The slider includes a fullscreen mode where each slide stretches to 100% the height of the viewport.

Markup

<div data-uk-slider>

    <div class="uk-slider-container">
        <ul class="uk-slider uk-slider-fullscreen">
            <li>...</li>
            ...
        </ul>
    </div>

</div>

JavaScript options

Option Possible value Default Description
center boolean false Center items mode
threshold boolean true Mouse movement threshold in pixel until trigger element dragging
infinite boolean true Infinite scrolling
activecls string uk-active Class added on active item in center mode
autoplay false boolean Defines whether or not the slider items should switch automatically
pauseOnHover boolean true Pause autoplay when hovering a slider
autoplayInterval integer 7000 Defines the timespan between switching slider items

Init element manually

var slider = UIkit.slider(element, { /* options */ });

Events

Name Parameter Description
focusitem.uk.slider event, index, item On item focus

Membership