Display <hw:carousel>
View examples

Carousel

Slider/carousel powered by Embla Carousel. Wraps the carousel controller with navigation buttons, pagination dots, responsive options and CSS-variable sizing — all wired for you.

Requires embla-carousel: bun add embla-carousel (install it manually). The track geometry ships in resources/css/structural.css, which every preset imports; publish the controller itself with php artisan hotwire:controllers carousel only if you want to customize it.

Basic Usage

HTML
<hw:carousel slide-size="80%" slide-spacing="1rem" loop>
    @foreach ($photos as $photo)
    <img src="{{ $photo->url }}" alt="" class="w-full rounded-md"/>
    @endforeach
</hw:carousel>

Each direct child of the default slot is a slide. Slide width and gap come from slide-size / slide-spacing (CSS custom properties) — see sizing.

Props

Prop Type Default Description
id string|object|null generated Root id; accepts a model for cross-request identity
controller string carousel Stimulus identifier to mount — set to a subclass (e.g. gallery) to use Embla plugins/custom behavior
loop bool false Infinite looping
align string center start / center / end
axis string x x / y (vertical needs a height on the viewport)
slides-to-scroll int|string auto Slides advanced per move (auto paginates by the visible count)
drag-free bool false Momentum dragging without snapping
breakpoints ?array null Media-query → option overrides (e.g. responsive slides-to-scroll)
respect-motion-preference bool true Injects a prefers-reduced-motion breakpoint that disables the animation
options array [] Catch-all for Embla options (duration, containScroll, watchDrag, etc.); direction defaults from computed CSS and can be explicitly overridden
navigation bool true Render prev/next buttons
dots bool true Render pagination dots
slide-size ?string null --carousel-slide-size (e.g. 70%); responsive via Tailwind utilities
slide-spacing ?string null --carousel-slide-spacing (e.g. 1rem)
class / viewport-class / container-class string '' Classes for the root / viewport / container
dot-class string '' Class for each dot (active state via aria-[current=true]:)
dot-list-class string '' Class for the dot-list container (e.g. positioning)
dot-list-label string Choose slide aria-label for the dot-list container
nav-class string sensible Class for prev/next (disabled state via disabled:)
nav-wrapper-class string '' When set, wraps both nav buttons in a <div> with this class (e.g. group them bottom-left); empty leaves them loose
progress bool false Render a progress bar after the viewport (controller sets style.width from scroll progress)
progress-wrapper-class string '' Class for the progress bar wrapper (the track)
progress-class string '' Class for the progress bar fill element
counter bool false Render a "current / total" counter after the viewport
counter-class string '' Class for the counter wrapper

slides-to-scroll defaults to auto (Embla's is 1) so multi-slide layouts paginate by the visible count. Pass :slides-to-scroll="1" for one-at-a-time. Use : for integers (:slides-to-scroll="3").

Slots

Slot Purpose
default The slides (each direct child is a slide)
prev_button Custom previous-button content (defaults to ‹)
next_button Custom next-button content (defaults to ›)
dot_template Inner content for each dot button (the component renders the <button>; style it with dot-class)

The slot's own attributes merge onto the button the component renders — pass class (appended), aria-label (overrides the default), or any attribute:

HTML
<x-slot:prev_button class="rounded-full bg-white/80 p-2" aria-label="Previous slide">
    <svg><!-- chevron-left --></svg>
</x-slot:prev_button>

Responsive multi-slide (3-up desktop, 1-up mobile)

Slide width is CSS, advance count is an Embla option — use the same breakpoint in both:

HTML
<hw:carousel
    align="start"
    :breakpoints="['(min-width: 768px)' => ['slidesToScroll' => 3]]"
    class="[--carousel-slide-size:100%] [--carousel-slide-spacing:1rem] md:[--carousel-slide-size:33.333%]"
>
    @foreach ($photos as $photo)
    <img src="{{ $photo->url }}" alt="" class="w-full"/>
    @endforeach
</hw:carousel>

Custom navigation and dots

Prev/next take inner content via slots; dot appearance is set with dot-class (the component renders the dot <button> itself). The dot_template slot is only for content inside each dot — leave it off for plain dots.

HTML
<hw:carousel dot-class="h-1 w-6 rounded bg-white/40 transition-colors aria-current:bg-white">
    <x-slot:prev_button>
        <svg><!-- chevron-left --></svg>
    </x-slot:prev_button>
    <x-slot:next_button>
        <svg><!-- chevron-right --></svg>
    </x-slot:next_button>

    {{-- slides --}}
</hw:carousel>

Slides with custom markup

HTML
<hw:carousel class="relative"
                 slide-size="75%"
                 slide-spacing=".5rem"
                 :counter="true"
                 :progress="true"
                 loop
                 dot-list-class="absolute bottom-3 left-1/2 flex -translate-x-1/2 gap-1.5"
                 counter-class="bg-white/50 backdrop-blur w-16 justify-center inline-flex px-4 py-3 leading-none font-medium text-sm tracking-widest rounded-xl absolute top-5 right-5"
                 progress-class="h-1 bg-accent/80 transition-all duration-300 ease-in-out rounded-xl"
                 progress-wrapper-class="absolute top-3 left-1/2 -translate-x-1/2 w-32 rounded-2xl max-w-xs backdrop-blur bg-white/20 rounded-md h-1"
>
    @foreach ($photos as $photo)
    <div class="min-w-0 overflow-hidden">
        <img src="{{ $photo->url }}" alt="" class="w-full h-full rounded-md"/>
    </div>
    @endforeach

    <x-slot:prev_button
        class="absolute left-0 top-1/2 rotate-90- md:rounded-tr-md md:rounded-br-md -translate-y-1/2 bg-white/30 md:bg-white w-8 h-16 md:size-16 flex items-center justify-center">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
             stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
             class="lucide lucide-chevron-left-icon lucide-chevron-left">
            <path d="m15 18-6-6 6-6"/>
        </svg>
    </x-slot:prev_button>

    <x-slot:next_button
        class="absolute right-0 top-1/2 rotate-90- md:rounded-tl-md md:rounded-bl-md -translate-y-1/2 bg-white/30 md:bg-white w-8 h-16 md:size-16 flex items-center justify-center">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
             stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
             class="lucide lucide-chevron-right-icon lucide-chevron-right">
            <path d="m9 18 6-6-6-6"/>
        </svg>
    </x-slot:next_button>

    <x-slot:dot_template
        class="size-2.5 rounded-full bg-white/50 transition-colors aria-current:bg-white"></x-slot:dot_template>

</hw:carousel>

Vertical Slides example

HTML
<hw:carousel class="relative"
                 viewport-class="h-150"
                 container-class="flex-col"
                 slide-size="80%"
                 slide-spacing="1rem"
                 axis="y"
                 :navigation="false"
                 loop
>

    @foreach ($photos as $photo)
    <div class="min-h-0 overflow-hidden">
        <img src="{{ $photo->url }}" alt="" class="w-full h-full object-cover rounded-2xl "/>
    </div>
    @endforeach
</hw:carousel>

Fullscreen example

HTML
<hw:carousel class="relative h-screen"
                 dot-list-class="absolute bottom-6 left-6 flex gap-1.5"
                 nav-wrapper-class="absolute bottom-5 right-5 flex gap-2"
                 loop
>

    @foreach ($photos as $photo)
    <div class="min-w-0 overflow-hidden">
        <img src="{{ $photo->url }}" alt="" class="w-full h-screen"/>
    </div>
    @endforeach

    <x-slot:prev_button
        class="rounded-full bg-white/30 md:bg-white w-8 h-16 md:size-16 flex items-center justify-center text-3xl/none">
        &larr;
    </x-slot:prev_button>

    <x-slot:next_button
        class="rounded-full bg-white/30 md:bg-white w-8 h-16 md:size-16 flex items-center justify-center text-3xl/none">
        &rarr;
    </x-slot:next_button>

    <x-slot:dot_template
        class="size-2.5 rounded-full bg-white/50 transition-colors aria-current:bg-white"></x-slot:dot_template>

</hw:carousel>

Turbo

The component wires turbo:before-cache@window->carousel#teardownForCache, so the Embla instance is destroyed before a Turbo snapshot and rebuilt on restore. Any data-action you add is unioned with it.

See the controller docs for events, the markup contract, axis handling and more.

Styling hooks

The component exposes stable data-slot hooks for preset and application CSS:

  • data-slot="carousel"
  • data-slot="carousel-progress"
  • data-slot="carousel-counter"
  • data-slot="carousel-prev-button"
  • data-slot="carousel-next-button"
  • data-slot="carousel-dot-button"
  • data-slot="carousel-dot-list"
  • data-slot="carousel-progress-wrapper"
  • data-slot="carousel-viewport"
  • data-slot="carousel-container"
  • data-slot="carousel-nav-wrapper"