Skip to main content
PimentCSS v1.0.1, what's new
Home

Carousel

Scrollable track, arrows, and scrollbar affordances.

Styles live in scss/components/_carousel.scss. Combine slide content (your markup) with .carousel controls; the live demos below show two compositions plus the control primitives.

Anatomy

PartClassRole
Block.carouselFlex row: prev arrow + scroll bar + next arrow (gap 16px, max 640px)
Arrow.carousel__arrow48×48px round button; --prev mirrors the icon
Scroll bar.carousel__scrollbarTrack + thumb; use as slider when wired to slides
Doc widget.pdoc-carousel-widgetDoc-only wrapper: viewport + aria-live status + controls
Slide[data-carousel-slide]One panel; toggle hidden + aria-hidden from JS

Prerequisites

  • PimentCSS installed, Installation.
  • Icons, ph-arrow-right at 24px via ph() (Phosphor in this doc).
  • Slides, any HTML (image, text, cards); keep one visible slide at a time.
  • Script, call wireAllCarousels() after DOM ready (see interactive section).

Two widget patterns share the same .carousel controls. Use arrow keys on the carousel region or the scroll bar (slider). Status text updates in aria-live="polite".

Split layout from min-width: 30rem: visual block + title and body copy. Decorative gradients use role="img" and a text alternative.

Same controls and behavior without a media column. Useful for quotes, KPIs, or legal notices.

48px circular buttons with a 2px action border. Doc-only .carousel__arrow--hover and .carousel__arrow--focus; production uses :hover and :focus-visible.

The scroll bar is a role="slider" when it reflects slide position (aria-valuenow, aria-valuemin, aria-valuemax). Default height is 2px; it grows to 4px on :hover. Use the interactive lab first, then compare the static state references below.

Static references (doc-only modifiers for focus/hover height previews):

Use when slide content lives elsewhere (for example a full-width hero). Mark a decorative bar with aria-hidden="true".

Add data-carousel-live on .pdoc-carousel-widget (full carousel) or data-carousel-scrollbar-live on .pdoc-carousel-scrollbar-lab (scroll bar only). Call wireAllCarousels() after load.

Class reference

ClassDescription
.carouselControl row (flex, gap 16px, max-width 640px)
.carousel__arrow48×48px prev/next button
.carousel__arrow--prevFlips arrow icon (scaleX -1)
.carousel__scrollbarTrack container (slider when wired)
.carousel__scrollbar-thumbProgress thumb; position with left
.pdoc-carousel-widgetDoc layout: viewport + status + controls
.pdoc-carousel-widget__slideSingle slide panel
.pdoc-carousel-widget__mediaDecorative visual block (doc demos)

Customize (Sass)

  1. Override max width, gaps, arrow size, and scroll bar metrics.
    @use "pimentcss-design-system" with (
      $carousel-max-width: 40rem,
      $carousel-gap: 1rem,
      $carousel-arrow-size: 3rem,
      $carousel-scrollbar-thumb-width: 37.5%
    );
  2. Run after editing _carousel.scss.
    npm run build:css

Accessibility (RGAA / WCAG)

Carousel pattern

  • Region, role="region" + aria-roledescription="carousel" + concise aria-label.
  • Slides, role="group" + aria-roledescription="slide"; hide inactive slides with hidden and aria-hidden="true".
  • Status, aria-live="polite" text (slide x of y + title) updated on change.
  • Controls, labeled prev/next; disable at ends; scroll bar as role="slider" when it reflects position.
  • Keyboard, Arrow Left/Right on the widget; Home/End on the slider; focus ring remains visible.
  • Images, real content images need alt; decorative blocks use role="img" + aria-label.

Next steps