Monsoon v0.2.0
Made by Alexandre Kohler Star

Interactive

Autoplay carousel

Adds autoplay to the CSS carousel: pauses on hover, on focus, in a background tab and with reduced motion, has a play and pause button, and the current dot fills up until the next slide. Needs monsoon.js.

Interactive7 classesNeeds monsoon.jsLight and dark

Needs monsoon.js. The styles work on their own, and the behavior comes from the optional interactive layer: add <script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script> or import 'monsooncss/js'. See the interactive layer.

Example

JavaScript API

Attribute

data-m-carousel-auto

Options

OptionDescription
data-m-carousel-auto-interval="4000"
data-m-carousel-auto-force (play even with reduced motion)

Methods

MethodDescription
Monsoon.carouselAuto(el).next()
Monsoon.carouselAuto(el).prev()
Monsoon.carouselAuto(el).go(2)
Monsoon.carouselAuto(el).play()
Monsoon.carouselAuto(el).pause()

Events

EventDescription
monsoon:slide { index }

Classes

7 classes. Click a name to copy it. Utilities on the same element always win over component defaults, so any of them can be adjusted with plain utility classes.

ClassTypeWhat it does

Usage

The styles ship inside the same stylesheet as the utilities, and the behavior comes from the optional monsoon.js script, which enhances any element with a matching data-m attribute, including markup added later.

index.html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script>

<!-- Autoplay carousel: start from the base class, then add modifiers -->
<div class="carousel-auto max-w-xl" data-m-carousel-auto data-m-carousel-auto-interval="4000">
  <div class="carousel carousel-full">
    <div id="auto-1" class="carousel-item"><div class="aspect-video w-full bg-gradient-to-br from-primary to-accent grid place-items-center text-white text-xl font-semibold">Plan</div></div>
    <div id="auto-2" class="carousel-item"><div class="aspect-video w-full bg-gradient-to-br from-info to-success grid place-items-center text-white text-xl font-semibold">Build</div></div>
    <div id="auto-3" class="carousel-item"><div class="aspect-video w-full bg-gradient-to-br from-warning to-danger grid place-items-center text-white text-xl font-semibold">Ship</div></div>
  </div>
  <nav class="carousel-nav"><a class="carousel-dot" href="#auto-1" aria-label="Slide 1"></a><a class="carousel-dot" href="#auto-2" aria-label="Slide 2"></a><a class="carousel-dot" href="#auto-3" aria-label="Slide 3"></a></nav>
</div>

Theme it with --seed on any ancestor, for example style="--seed: #0d9488", and force a scheme with class="dark" or class="light" on a wrapper.

Accessibility

  • Wrap navigation in nav with an aria-label when there is more than one on the page, and mark the current link with aria-current="page".
  • Every interactive part shows a visible focus ring with :focus-visible, and tone colors pair with -foreground tokens that keep text at 4.5:1 or better in light and dark mode.

No recent searches

Try , , or .

Recent

Loading the search index

No results for ""

Check the spelling, or search a class name such as px-4.