Skip to content

Card carousel

Turn an ordinary grid of cards into a responsive, infinitely wrapping carousel. The carousel accepts any number of cards. Five cards arranged as three plus two is just one example: the card count and the number visible at once are independent.

The carousel is a website extension in the managed pdk.js and pdk.css assets. It does not need a Python-Markdown extension table. Projects prepared with Adopt already load these assets. After upgrading Prodockit, refresh them:

pdk shared-files --apply

For a manually configured project, load the managed files in zensical.toml and enable Markdown inside HTML containers:

[project]
extra_css = ["stylesheets/pdk.css"]
extra_javascript = ["javascripts/pdk.js"]

[project.markdown_extensions.md_in_html]

Keep any existing stylesheet, JavaScript and Markdown-extension settings when adding these entries. The files ship in the Prodockit wheel and use the existing shared-file manifest and adoption mechanisms; there is no carousel library or runtime CDN dependency. Existing template projects receive them through their normal package upgrade and pdk shared-files --apply workflow.

Write the Markdown

Add pdk-carousel to an existing grid cards container and give it a meaningful accessible name. Its direct list items become the carousel sequence in source order, regardless of how many grid rows they originally occupied.

<div class="grid cards pdk-carousel pdk-carousel-tiles" markdown data-carousel-label="Featured resources">

-   __Explore__

    Find your starting point.

    [Read the overview](../authoring.md)

-   __Write__

    Structure your document with clear headings. Give each section a meaningful
    title so readers can find the information they need.

    [Use headings](headings.md)

-   __Connect__

    Link to sections, figures and tables.

    [Add cross-references](refs.md)

-   __Reference__

    Cite your sources consistently.

    [Use a bibliography](bibliography.md)

-   __Publish__

    Share your work online and in print.

    [Generate a PDF](../pdf.md)

</div>

Live example: five cards

Use the small left and right arrow buttons at the bottom of the cards, drag a card body with the mouse, or focus an arrow button and press the left or right arrow key. The sequence wraps in both directions. On touchscreens, swipe horizontally over the card body; links and form controls retain their normal interaction. Drag farther to move through several cards in one gesture.

View the Markdown

To view the Markdown for this page, click the eye icon at the top right of the page.

Live example: countries, three cards wide

Choose a photograph or country name to open that country in Wikipedia. This six-card carousel shows three equal-height image tiles on a desktop page and fewer on narrow screens. The photos are local 640 × 426 pixel JPEGs, cropped to a consistent landscape shape, with photographer credits below each tile. The photos fill each card edge to edge, with an 8-pixel gap between neighbouring cards.

Use data-carousel-visible="3" data-carousel-min-width="160" for this compact three-card layout. Add data-carousel-image-fill="true" data-carousel-gap="8" for edge-to-edge photos and a small gap. Add the pdk-carousel-image class to card images to keep their displayed dimensions consistent. The pdk-carousel-tiles class keeps these short picture cards together on a printed page. The picture and country-name links remain usable, while dragging a picture or the card body moves the carousel.

Live example: automatic rotation

This separate seven-card example shows half-card previews on both edges and slides smoothly to the next card every four seconds. Hovering over it, focusing any of its content, or hiding the browser tab pauses rotation. Use P while a carousel arrow has focus to keep it paused after leaving. The pause button is hidden in this example with data-carousel-pause="false"; omit that option to show the pause/resume button. Reduced-motion preferences disable automatic rotation and transitions. The cards progress from white to dark grey; the four darkest cards use white text to maintain readable contrast.

Keyboard arrows apply only to the carousel region and its controls, so links, text inputs and other card content keep their normal keyboard behaviour. Offscreen cards and decorative previews are hidden from the accessibility tree and keyboard focus. Manual navigation announces the visible card numbers; autoplay does not repeatedly interrupt screen-reader users. The visible count and list of card numbers appear below the cards unless data-carousel-position="false".

Live example: numbered cards without wrapping

Follow the Eiffel Tower construction through 18 dated photographs, from 10 August 1887 to 12 March 1889. Each card has a top-right badge from 1/18 to 18/18. Use the arrows or drag to move through the sequence; navigation stops at the first and last window. Six equal-height cards appear on wide screens, with an 8-pixel gap and fewer cards on narrow screens.

Source: supplied PublicDomainArchive montage; dates follow the original captions. View the complete construction sequence.

Enable badges with data-carousel-badges="true". Choose any of top-left, top-right, bottom-left or bottom-right with data-carousel-badge-corner; an omitted or invalid corner uses top-right. Each badge keeps its original card number as the carousel moves. Badges are independent of the optional position label below the carousel.

Set data-carousel-loop="false" to stop wrapping. This differs from data-carousel-autoplay="false", which turns off automatic advancement. You can combine finite navigation with autoplay; rotation stops at the final window. Navigating back allows automatic advancement again unless paused. With half-card previews enabled, the first and last windows leave the missing neighbour's side empty instead of repeating a card.

Override the badge styles in stylesheets/extra.css, or set them on an individual carousel as above:

.pdk-carousel {
  --pdk-carousel-badge-color: #ffffff;
  --pdk-carousel-badge-bg: rgba(0, 0, 0, 0.75);
  --pdk-carousel-badge-inset: 0.5rem;
  --pdk-carousel-badge-padding: 0.15rem 0.45rem;
  --pdk-carousel-badge-font-size: 0.75rem;
  --pdk-carousel-badge-radius: 1rem;
}

Bottom badges sit above the arrow-control row. Choose text and background colours that remain legible over your pictures. Badges do not receive focus or intercept clicks and dragging; assistive technology uses each slide's existing position label. Badges are hidden in browser print and absent from generated PDFs, which retain every original card once in source order. Without JavaScript, cards remain a static grid.

Configure only when needed

Use Table 28.1 to set a carousel's accessible name, visible card count and optional automatic rotation.

Each carousel has independent controls and state. Empty grids remain unchanged; when all cards fit, navigation and automatic rotation are disabled. All cards have the same height, measured from the tallest original card at the current width, so the carousel stays steady as it moves. The smooth sliding transition also works at the loop boundary. Decorative edge copies are inert, hidden from assistive technology and excluded from print; their IDs and local references are remapped to avoid duplicates. Original card DOM order stays unchanged.

Without JavaScript, or in browsers lacking the required enhancement APIs, the complete ordinary grid remains available. Browser print shows every original card once in source order and removes carousel controls, clipping and animation, even after the carousel has advanced.

pdk pdf consumes the static card HTML without running JavaScript. It prints all original cards in rows matching the authored visible-card count: data-carousel-visible="2" prints two across, and "3" prints three across (the default). Partial final rows retain their column widths. Browser print uses the number of full cards currently visible on screen; decorative half-card previews do not add columns. Long cards may continue onto another page. Ordinary grid cards keep their existing PDF layout.

Style the arrow buttons

Add overrides to docs/stylesheets/extra.css to change the small translucent grey buttons and black arrows at the bottom corners of the cards. Scope the selector to a particular carousel class when different carousels need different styles.

.pdk-carousel {
  --pdk-carousel-button-bg: rgba(238, 238, 238, 0.75);
  --pdk-carousel-button-color: #000000;
  --pdk-carousel-button-hover-bg: rgba(221, 221, 221, 0.9);
  --pdk-carousel-button-border: #cccccc;
  --pdk-carousel-button-size: 1.6rem;
  --pdk-carousel-button-radius: 0.2rem;
}