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.

  • Slide 1

  • Slide 2

  • Slide 3

  • Slide 4

  • Slide 5

  • Slide 6

  • Slide 7

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.

  • Lazyload Image 1

    The Slider 1

    The slider text for slider 1 at the bottom here.

  • Lazyload Image 2

    The Slider 2

    The slider text for slider 2 at the bottom here.

  • Lazyload Image 3

    The Slider 3

    The slider text for slider 3 at the bottom here.

  • Lazyload Image 4

    The Slider 4

    The slider text for slider 4 at the bottom here.

  • Lazyload Image 5

    The Slider 5

    The slider text for slider 5 at the bottom here.

  • Lazyload Image 6

    The Slider 6

    The slider text for slider 6 at the bottom here.

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)

  • 1

  • 2

  • 3

HTML



<div class="hpu-slider splide" aria-label="Slide 3a" data-hpu="slider">
    ...
</div>

Teal

  • 1

  • 2

  • 3

HTML



<div class="hpu-slider color-theme-1st splide" aria-label="Slide 3b" data-hpu="slider">
    ...
</div>

White

  • 1

  • 2

  • 3

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.

  • Slide 1

  • Slide 2

  • Slide 3

  • Slide 4

  • Slide 5

  • Slide 6

  • Slide 7

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



let slider = new HPU.Slider('#sliderId', {options});

Carousel Methods

When a slider is set programmatically to define options, the method defines what to do to the slider.

JS



let slider = new HPU.Slider('#id', {options});
slider.slide();

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.

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

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



let slide5a = new HPU.Slider('#slide5a', {
    gap : '.5rem',
    height : '10rem',
    perPage : 3
});

// Manually enable the defined slider
slide5a.slide();

1 Slide Per move: perMove : 1 with type : 'loop'.

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

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



let slide5b = new HPU.Slider('#slide5b', {
    gap : '.5rem',
    height : '10rem',
    perMove : 1,
    perPage : 3,
    type : 'loop'
});

// Manually enable the defined slider
slide5b.slide();

focus:0: The indicator dots represent number of slides instead of page(s), and moves active slide instead of page(s).

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

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



let slide5c = new HPU.Slider('#slide5c', {
    focus : 0,
    gap : '.5rem',
    height : '10rem',
    perPage : 3
});

// Manually enable the defined slider
slide5c.slide();

Center Focus with focus:'center' and let the change the focus by page instead of by slide with type:'loop'.

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

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



let slide5d = new HPU.Slider('#slide5d', {
    focus : 'center',
    gap : '.5rem',
    height : '10rem',
    perPage : 3,
    type : 'loop'
});

// Manually enable the defined slider
slide5d.slide();

drag:'free': try flicking the slides

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

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



let slide5e = new HPU.Slider('#slide5e', {
    drag : 'free',
    focus : 'center',
    gap : '.5rem',
    height : '10rem',
    perPage : 3,
    type : 'loop'
});

// Manually enable the defined slider
slide5e.slide();

autoWidth:true: width determined by the content width

  • Slide 1 with longer content

  • Slide 2 medium content

  • Slide 3 contents

  • Slide 4 the contents

  • Slide 5 the looong content

  • Slide 6 meh content

  • Slide 7 the bleh

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



let slide5f = new HPU.Slider('#slide5f', {
    autoWidth : true,
    focus : 'center',
    gap : '.5rem',
    height : '10rem',
    perPage : 3,
    type : 'loop'
});

// Manually enable the defined slider
slide5f.slide();

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.

  • Slide 1

  • Slide 2

  • Slide 3

  • Slide 4

  • Slide 5

  • Slide 6

  • Slide 7

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

  • Lazyload Image 1
  • Lazyload Image 2
  • Lazyload Image 3
  • Lazyload Image 4
  • Lazyload Image 5
  • Lazyload Image 6
  • Lazyload Image 7
  • Lazyload Image 8
  • Lazyload Image 9
  • Lazyload Image 10
  • Lazyload Image 11
  • Lazyload Image 12
  • Lazyload Image 13
  • Lazyload Image 14
  • Lazyload Image 15
  • Lazyload Image 1
  • Lazyload Image 2
  • Lazyload Image 3
  • Lazyload Image 4
  • Lazyload Image 5
  • Lazyload Image 6
  • Lazyload Image 7
  • Lazyload Image 8
  • Lazyload Image 9
  • Lazyload Image 10
  • Lazyload Image 11
  • Lazyload Image 12
  • Lazyload Image 13
  • Lazyload Image 14
  • Lazyload Image 15

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.