Carousel Sliders
Displays a series of images, text, or other content items in a rotating, sliding format. HPUCSS Sliders powered by SplideJS.
Default Carousel
Basic version of the carousel slider that comes with default styling and functionality.
NOTE: the .is-active class is used to show which slide is currently active. In this example, the active slide is using the same color as the .hpu-bg-6th. Please refer to HPU Colors for usage. The .is-active can be ignored especially when having an image carousel slider.
Also, the splide classes use double underscore: splide__track, splide__list, and splide__slide.
Image Carousel with Text Overlay and Image Lazyload
In the example below, the text is applied on the slider along with background color overlay and lazyLoad background image. Please refer to HPU Colors for usage guides.
Lazy loading is a technique used to defer the loading of images on a webpage until they are needed.
By default, lazyLoad option is enabled with 'nearby' mode, which loads only the images near the active slide. Additionally, the img tag must use the data-splide-lazy attribute instead of the src attribute. This effect can be seen in the browser's developer feature.
Also, cover is set to true by default to let the image to cover up the entire area of the carousel slider.
More info about the options mentioned above are available in the options table.
Carousel Controls and Indicator Themes
Adjust the controls and indicator colors by adding color classes to the wrapper, ensuring optimal content contrast: .hpu-slider .color-theme-{color} .splide. Please refer to HPU Colors for usage guides.
Black (default)
HTML
div class="hpu-slider splide" aria-label="Slide 3a" data-hpu="slider"
...
/div
Teal
HTML
div class="hpu-slider color-theme-1st splide" aria-label="Slide 3b" data-hpu="slider"
...
/div
White
HTML
div class="hpu-slider color-theme-white splide" aria-label="Slide 3d" data-hpu="slider"
...
/div
Programmatic Carousel Sliders
Sliders can be activated programmatically with options available to customize their behavior. When using this approach, simply add the id to the parent wrapper, then remove the data-hpu attribute, then call the id value into your script.
Carousel Options
Set of configurable parameters that define the behavior and functionality of a carousel slider. To change the slider's behavior, simply add an option right next to the selector as shown:
JS
slidernew HPU'#sliderId',
Carousel Methods
When a slider is set programmatically to define options, the method defines what to do to the slider.
JS
slidernew HPU'#id',
slider();
Multiple Slides Carousels
Featuring different variety of multiple slides carousels.
Examples below have height:'10rem' and gap:'.5rem' for compact examples.
Basic Multiple Slides with perPage : 3.
HTML
div class="hpu-slider color-theme-dark-gray splide" id="slide3a aria-label="Slide 3a"
div class="splide__track"
ul class="splide__list"
li class="splide__slide hpu-bg-gray hpu-d-flex flex-ai-center flex-jc-center".../li
...
/ul
/div
/div
JS
slide5anew HPU'#slide5a'
1 Slide Per move: perMove : 1 with type : 'loop'.
HTML
div class="hpu-slider color-theme-dark-gray splide" id="slide5b aria-label="Slide 5b"
div class="splide__track"
ul class="splide__list"
li class="splide__slide hpu-bg-gray hpu-d-flex flex-ai-center flex-jc-center".../li
...
/ul
/div
/div
JS
slide5bnew HPU'#slide5b'
focus:0: The indicator dots represent number of slides instead of page(s), and moves active slide instead of page(s).
HTML
div class="hpu-slider color-theme-dark-gray splide" id="slide5c aria-label="Slide 5c"
div class="splide__track"
ul class="splide__list"
li class="splide__slide hpu-bg-gray hpu-d-flex flex-ai-center flex-jc-center".../li
...
/ul
/div
/div
JS
slide5cnew HPU'#slide5c'
Center Focus with focus:'center' and let the change the focus by page instead of by slide with type:'loop'.
HTML
div class="hpu-slider color-theme-dark-gray splide" id="slide5d aria-label="Slide 5d"
div class="splide__track"
ul class="splide__list"
li class="splide__slide hpu-bg-gray hpu-d-flex flex-ai-center flex-jc-center".../li
...
/ul
/div
/div
JS
slide5dnew HPU'#slide5d'
drag:'free': try flicking the slides
HTML
div class="hpu-slider color-theme-dark-gray splide" id="slide5e aria-label="Slide 5e"
div class="splide__track"
ul class="splide__list"
li class="splide__slide hpu-bg-gray hpu-d-flex flex-ai-center flex-jc-center".../li
...
/ul
/div
/div
JS
slide5enew HPU'#slide5e'
autoWidth:true: width determined by the content width
HTML
div class="hpu-slider color-theme-dark-gray splide" id="slide5f aria-label="Slide 5f"
div class="splide__track"
ul class="splide__list"
li class="splide__slide hpu-bg-gray hpu-d-flex flex-ai-center flex-jc-center hpu-px-1".../li
...
/ul
/div
/div
JS
slide5fnew HPU'#slide5f'
Vertical Carousel Slider with Mouse Wheel
Slides move vertically (up and down) instead of horizontally (left and right). To prevent the slides from changing too quickly, you can enable the waitForTransition by setting it to true. This ensures that the mouse wheel waits for the current slide transition to complete before moving to the next slide.
Thumbnail Carousel Slider With Responsive Behavior
Carousel sliders can be synchronized, with the main slider on top and a thumbnail navigation slider below. For both of the sliders, pagination must be set to false, and for the top slider, arrows must also be set to false.
In the example below, the carousel type is set to 'fade', allowing seamless looping with the fade transition. Responsive behavior is configured also using the breakpoints option to specify when and how the carousel should adapt to different device sizes.
CURRENT SCREEN SIZE: xs sm md lg xl xxl
Carousel Accessibility
Carousel sliders are a visually appealing way to present content compactly. However, they can pose accessibility challenges that need careful attention. SplideJS offers a solid foundation with built-in accessibility features, but additional enhancements are necessary to ensure the carousel is fully accessible to all users.
One essential enhancement is adding the aria-label attribute to every carousel slider container. This provides a clear description of the carousel's content, improving the experience for users relying on assistive technologies:
HTML
div class="splide" id="..." aria-label="The Great Slider"
...
/div
The aria-label can also be defined by referencing the title of the carousel slider. Instead of using aria-label, it's recommended to use aria-labelledby assigning the id of the title as its value. This approach allows screen readers to announce the title directly, providing a more descriptive and contextually relevant experience for users:
HTML
div class="splide" id="..." aria-labelledby="theSlider"
h1 id="theSlider"
...
/h1
/div
Finally, the default autoplay interval is set to 5000 milliseconds, providing a comfortable pacing for most users. For an optimal experience, intervals between 5000 and 10000 milliseconds are recommended, as shorter durations can feel rushed.
For more accessibility information, check out the SplideJS Accessibility Guides.