Carousel

Slides that rotate, one per row.

When to use it

A few images or messages of equal weight where the space is short: photos of a place, quotes from clients.

When not to

Important content: most visitors never see the slides after the first. For images people should look at, a gallery shows them all at once.

Accessibility

Slides move only when the visitor asks, or with the autoplay variant, which stops on hover and focus and never runs when the visitor's system asks for reduced motion. Buttons to go back and forth work with the keyboard and are named for screen readers. Without its script, the slides are a plain list.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

The carousel example as the component library shows it in the default theme

Fields

What the component’s dialog asks for. In a Doc, keyed rows start with the key; rows in order follow the order below. Each row is one item, its cells in the order of the fields.

Field

Key

Kind

Required

Image

image

An image from the assets, with its description

No

Text

text

Text with headings, lists, links and bold

Yes

Link

link

A link: its text and address

No

Variants

A variant changes how the component looks. Write it in parentheses after the name in the table’s first cell, several separated by commas.

Variant

Write in the first cell

Images only

carousel (gallery)

Plays by itself

carousel (autoplay)

Warnings it can raise

The editor and the build say these when a block of this component needs a fix. All warnings are listed in the warnings reference.

Code

What it says

single_item_container

A {block} has a single item; a simpler component would do.

unnamed_item

Item {index} of a {block} has no title; a generic name is used.

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table: The first row of the table here only names the columns; the Doc table is the rows below it.

Image

Text

Link

carousel

[Image]

Alps — Seven days hut to hut.

See trip (https://example.com/alps/)

[Image]

Desert — Nights under the stars.

See trip (https://example.com/desert/)

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "carousel",
  "variants": [
    "gallery"
  ],
  "rows": [
    [
      {
        "image": "Alpine lake"
      },
      {
        "title": "Alps",
        "text": "Seven days hut to hut."
      },
      {
        "link": "See trip",
        "href": "https://example.com/alps/"
      }
    ],
    [
      {
        "image": "Desert dunes"
      },
      {
        "title": "Desert",
        "text": "Nights under the stars."
      },
      {
        "link": "See trip",
        "href": "https://example.com/desert/"
      }
    ]
  ]
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

carousel

The component

carousel__controls

A part of it

carousel__indicator

A part of it

carousel__indicators

A part of it

carousel__next

A part of it

carousel__pause

A part of it

carousel__previous

A part of it

carousel__slide

A part of it

carousel__slides

A part of it

carousel--gallery

A variant

carousel--autoplay

A variant

carousel--enhanced

Added by the component itself: a setting, or what its script does

The HTML the example above writes, as the component library builds it in the default theme:

html
<section class="carousel" aria-roledescription="carousel" aria-label="Highlights" data-carousel>
<div class="carousel__slides" id="carousel-1-slides">
<div class="carousel__slide" role="group" aria-roledescription="slide" aria-label="1 of 2">
<div class="teaser teaser--hero hero">
<div class="teaser__media"><img src="/assets/img/5521e01d770e-1600.webp" srcset="/assets/img/5521e01d770e-400.webp 400w, /assets/img/5521e01d770e-800.webp 800w, /assets/img/5521e01d770e-1600.webp 1600w" sizes="(max-width: 800px) 100vw, 800px" alt="Alpine lake" width="1800" height="900" fetchpriority="high" decoding="async"></div>
<div class="teaser__body">
<h2 class="teaser__title"><a href="https://example.com/alps/">Alps</a></h2>
<div class="teaser__text"><p>Seven days hut to hut.</p></div>
<div class="teaser__actions"><a class="button" href="https://example.com/alps/">See trip</a></div>
</div>
</div>
</div>
<div class="carousel__slide" role="group" aria-roledescription="slide" aria-label="2 of 2">
<div class="teaser teaser--hero hero">
<div class="teaser__media"><img src="/assets/img/5521e01d770e-1600.webp" srcset="/assets/img/5521e01d770e-400.webp 400w, /assets/img/5521e01d770e-800.webp 800w, /assets/img/5521e01d770e-1600.webp 1600w" sizes="(max-width: 800px) 100vw, 800px" alt="Desert dunes" width="1800" height="900" loading="lazy" decoding="async"></div>
<div class="teaser__body">
<h2 class="teaser__title"><a href="https://example.com/desert/">Desert</a></h2>
<div class="teaser__text"><p>Nights under the stars.</p></div>
<div class="teaser__actions"><a class="button" href="https://example.com/desert/">See trip</a></div>
</div>
</div>
</div>
</div>
<div class="carousel__controls" hidden>
<button class="carousel__previous" type="button" aria-controls="carousel-1-slides">Previous</button>
<button class="carousel__next" type="button" aria-controls="carousel-1-slides">Next</button>
<div class="carousel__indicators">
<button class="carousel__indicator" type="button" aria-label="Show slide 1"></button>
<button class="carousel__indicator" type="button" aria-label="Show slide 2"></button>
</div>
</div>
</section>

Visitor texts

Texts it shows visitors, in the page’s language. Every one is in the visitor texts reference.

Key

Text

site.carousel.label

Highlights

site.carousel.previous

Previous

site.carousel.next

Next

site.carousel.pause

Pause

site.carousel.play

Play

site.carousel.slide

{n} of {total}

site.carousel.goTo

Show slide {n}

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/carousel.js
  • src/components/carousel/carousel.liquid
  • src/components/carousel.client.js

It has a browser script, the .client.js file above. Without it the component still shows all its content; the script only adds behaviour.