Create a responsive slideshow with images and videos.
The Slideshow component is fully responsive and supports touch and swipe navigation as well as mouse drag for desktops. When swiping between slides, the animation literally sticks at your fingertips or mouse cursor. It accelerates to keep up with your pace when you click through the previous and next navigation. All animations are hardware accelerated for a smoother performance.
To apply this component, add the data-uk-slideshow attribute to a container element and create a list of slides with the .uk-slideshow-items class.
Add an image in the background of each slide using the data-uk-cover attribute from the Cover component.
Note To lazy load images in the
slides, use the loading="lazy" attribute. The Slideshow will automatically
remove the attribute from images in adjacent slides.
By default, the slideshow uses a slide animation. You can set the animation option to use a different animation. Possible values are as follows:
| Animation | Description |
|---|---|
slide | Slides slide in side by side. |
fade | Slides fade in. |
scale | Slides are scaled up and fade out. |
pull | Slides are pulled from the deck. |
push | Slides are pushed to the deck. |
To activate autoplay, just add the autoplay: true option to the attribute. You can also set the interval in milliseconds between switching slides using autoplay-interval: 6000. To pause autoplay when hovering the slideshow, use pause-on-hover: true.
By default, infinite scrolling is enabled. To disable this behavior, just add the finite: true option to the attribute.
The slideshow always takes up the full width of its parent container. The height adapts according to the defined ratio. To change the default ratio of 16:9, just add the ratio option to the attribute. It’s recommended to use the same ratio as the background images. For example, just use their width and height, like 1600:1200.
By default, the slideshow height adopts the defined ratio. A minimum or maximum height can be set using the min-height and max-height options.
To navigate through your slides, just use the data-uk-slideshow-item attribute. To target the slides, set the attribute of every nav item to the index number of the respective slideshow item. The elements with the data-uk-slideshow-item attribute need to be inside the data-uk-slideshow container. Setting the attribute to next and previous will switch to the adjacent slides.
The flexibility of the Slideshow component allows you to use any of the other UIkit components to navigate through items. For example the Slidenav, Dotnav and Thumbnav components can be used to style the slideshow navigations.
If there is no item specific content in the navigation items, you can also add the .uk-slideshow-nav class instead of adding navigation items manually. It will generate its items automatically using <li><a href></a></li> as markup. This is a useful shortcut when using the Dotnav.
Instead of a step-by-step animation using navigation controls, the slideshow can use a stepless parallax animation based on its scroll position in the viewport. Just add parallax: true to the attribute. If a navigation is set in the markup it won’t be clickable but it will get the active state of the current slide.
To adjust the parallax duration, set the parallax-start and parallax-end options. The parallax-start option defines when the animation starts. The default value of 0 means that the slideshow’s top border and viewport’s bottom border intersect. The end option defines when the animation ends. The default value of 0 means that the slideshow’s bottom border and the viewport’s top border intersect. Values can be set in any dimension units, namely vh, % and px. The % unit relates to the slideshow’s height. Both options allow basic mathematics operands, + and -.
The slideshow is not restricted to images. Other media, like videos, can be positioned in the background of each slide using the data-uk-cover attribute from the Cover component. Videos are muted, and play automatically. The video will pause whenever it’s not visible, and resume once it becomes visible again.
To add a simple Ken Burns effect, wrap the image with a div and add the .uk-position-cover and .uk-animation-kenburns classes. You can also apply the .uk-animation-reverse or one of the .uk-transform-origin-* classes to modify the effect.
Add content overlays using the Position component. It allows you to place the content anywhere inside the slide.
Add the data-uk-slideshow-parallax attribute to any element inside the slides to animate it together with the slideshow animation. Add an option with the desired animation values for each CSS property you want to animate. Define at least one start and end value. It can be done by passing two values separated by a comma.
This functionality is inherited from the Parallax component, and it allows animating CSS properties depending on the scroll position of the slideshow animation. Take a look at the possible properties that can be animated.
In the example above, the content will start at 100 and animate halfway to 0 while the slide moves in. When the slide starts again to move out, the content will continue to animate to -100. This works because the start and end values have the same distance. For different distances, three values are needed: Start (Slide animates in), Middle (Slide is centered), End (Slide animates out).
The next example defines different in and out animations. The content slides in by moving from 100 to 0 and fades out from 1 to 0.
The parallax attribute can be used to add additional effects to the slideshow animations. In the following example the push animation is extended by dimming out and scaling down the image when it’s sliding out.
Transition classes from the Transition component are triggered automatically inside slides. Contrary to the parallax effect, transitions are not attached to the slideshow animation and start playing independently after the slideshow animation.
Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more
| Option | Value | Default | Description |
|---|---|---|---|
animation | String | slide | Slideshow animation mode (slide, fade, scale, pull or push). |
autoplay | Boolean | false | Slideshow autoplays. |
autoplay-interval | Number | 7000 | The delay between switching slides in autoplay mode. |
draggable | Boolean | true | Enable pointer dragging. |
easing | String | ease | The animation easing (CSS timing functions or cubic-bezier). |
finite | Boolean | false | Disable infinite sliding. |
pause-on-hover | Boolean | true | Pause autoplay mode on hover. |
index | Number | 0 | Slideshow item to show. 0 based index. |
velocity | Number | 1 | The animation velocity (pixel/ms). |
ratio | Boolean, String | 16:9 | The ratio. (false prevents height adjustment) |
min-height | Boolean, Number | false | The minimum height. |
max-height | Boolean, Number | false | The maximum height. |
Learn more about JavaScript components.
The following events will be triggered on elements with this component attached:
| Name | Description |
|---|---|
beforeitemshow | Fires before an item is shown. |
itemshow | Fires after an item is shown. |
itemshown | Fires after an item’s show animation has been completed. |
beforeitemhide | Fires before an item is hidden. |
itemhide | Fires after an item’s hide animation has started. |
itemhidden | Fires after an item’s hide animation has been completed. |
The following methods are available for the component:
Shows the slideshow item.
Starts the slideshow autoplay.
Stops the slideshow autoplay.
The Slideshow component adheres to the Carousel WAI-ARIA design pattern and automatically sets the appropriate WAI-ARIA roles, states and properties.
aria-roledescription property set to carousel.aria-live property.group role if the slideshow has only a previous/next navigation or the tabpanel role if it has a tab navigation, the aria-roledescription property set to slide and an aria-label property.The tab navigation adheres to the tab pattern.
tablist role.presentation role.tab role, the aria-selected state, the aria-controls property set to the ID of the respective slide, and an aria-label property.The previous/next navigation adheres to the button pattern.
aria-label property, the aria-controls property set to the ID of the slide list, and if an <a> element is used, the button role.Autoplay stops when any element in the Slideshow component receives focus. The tab navigation can be accessed through the keyboard using the following keys.
The Slideshow component uses the following translation strings. Learn more about translating components.
| Key | Default | Description |
|---|---|---|
next | Next Slide | aria-label for next slide button. |
previous | Previous Slide | aria-label for previous slide button. |
slideX | Slide %s | aria-label for pagination slide button. |
slideLabel | %s of %s | aria-label for slide. |