Categories section

Three rows of category chips that scroll without end, the middle one the other way. Point at a row to stop it; the chip’s icon plays.

Get the code

This demo also exists as a standalone project — npm install && npm run dev, no changes needed.

npx giget@latest gh:lordicondev/ui-components/categories-section#standalone categories-section

Copies the categories-section folder of the standalone branch — where every demo lives on its own — into ./categories-section.

How it works

Define the element, put the icon in the markup, set the control's state. Then the parts that make this demo different.

Define the element Built-in triggers only. The rest of the script is one call that scrolls the rows.
import { defineElement } from '@lordicon/element';

// Registers <lord-icon> with its built-in triggers.
defineElement();
A row of chips Hovering anywhere on a chip plays its icon. Copies of the set fill the loop.
html
<!-- target points each icon at its chip, so the whole chip is the hover area. The
     track holds the set three times. The copies are hidden from screen readers and
     their chips have tabindex="-1", so Tab stops once at each chip. -->
<div class="row row--1">
    <div class="track">
        <ul class="set" aria-label="Creative skills">
            <li>
                <button class="chip chip--signal" type="button">
                    <lord-icon
                        class="chip__icon"
                        current-color
                        src="icons/system-solid-61-camera.json"
                        loading="interaction"
                        trigger="hover"
                        target=".chip"
                        aria-hidden="true"
                    >
                        <img alt="" src="icons/system-solid-61-camera.svg" />
                    </lord-icon>
                    photography
                </button>
            </li>
            ⋯
        </ul>
        <ul class="set" aria-hidden="true">
            ⋯
        </ul>
        <ul class="set" aria-hidden="true">
            ⋯
        </ul>
    </div>
</div>
Slide by one set, then start over One number moves the whole row, so the loop never shows a seam.
css
/* The track holds the chips three times. --progress from 0 to 1 slides it by one set,
   then it starts over. main.ts moves it. */
.row {
    overflow: clip;
    /* Room for the focus ring, which is 4px outside the chip. */
    padding-block: var(--space-4);
}

.track {
    --copies: 3;
    display: flex;
    width: max-content;
    transform: translateX(calc(var(--progress) * -100% / var(--copies)));
    will-change: transform;
}

.row--right {
    --direction: -1;
}
Slow to a stop, then pick up A row slows to a stop under the pointer, and picks up again after.
// One loop moves every row. A row that is not moving is not written to.
let last = performance.now();
const frame = (now: number) => {
    const elapsed = Math.min(Math.max(now - last, 0), MAX_STEP);
    last = now;
    for (const row of rows) {
        const { from, to, begin, duration, easing } = row.speed;
        row.rate = rateAt(from, to, (now - begin) / duration, easing);
        if (row.seek) {
            const p = seekTime
                ? Math.min(Math.max((now - row.seek.begin) / seekTime, 0), 1)
                : 1;
            row.progress =
                p < 1 ? wrap(row.seek.from + row.seek.by * easeInOut(p)) : row.seek.to;
            if (p === 1) row.seek = null;
        } else if (row.rate) {
            row.progress = advance(row.progress, elapsed, row.direction * row.rate, round);
        } else continue;
        row.track.style.setProperty('--progress', row.progress.toFixed(6));
    }
    requestAnimationFrame(frame);
};
if (rows.length) requestAnimationFrame(frame);
Chip colours One custom property per chip. Hover mixes it with black.
css
/* Each chip sets --chip, and hover darkens it. The icon is white like the text through
   current-color, and its placeholder through the filter. */
.chip {
    --chip-fill: var(--chip);
    --icon-filter: var(--filter-ink-inverse);

    display: flex;
    align-items: center;
    gap: var(--space-8);
    padding: var(--space-8) var(--space-16);
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--chip-fill);
    color: var(--ink-inverse);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
}

/* Only under a mouse: on a touch screen :hover stays on after the tap. */
@media (hover: hover) {
    .chip:hover {
        --chip-fill: color-mix(in oklab, var(--chip) 86%, black);
    }
}

Source files

The demo's own files, whole, at the paths the export uses.

categories-section.css 191 lines
css
@import '@shared/styles/index.css';

/* The chip colours are Figma variables that are not in the shared palette. */
.demo {
    --salvia: #6ea4d3;
    --yamabuki: #eeaa2b;
    --lilac: #de9ccf;
    --cinnamon: #d8957a;
    --moss: #4e8a54;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-48);
    min-height: 100dvh;
    padding: var(--space-64) 0;
}

.heading {
    display: flex;
    flex-direction: column;
    gap: var(--space-12);
    padding: 0 var(--gutter);
    text-align: center;
    text-wrap: balance;
}

.heading__title,
.heading__text {
    margin: 0;
}

.heading__title {
    font-size: clamp(var(--text-2xl), 4vw, var(--text-3xl));
    font-weight: 600;
    line-height: 1.2;
}

.heading__text {
    color: var(--ink-soft);
    font-size: var(--text-lg);
    line-height: var(--leading-lg);
}

/* The rows, as wide as the screen up to 2400px. Three sets fill that. */
.marquee {
    position: relative;
    display: grid;
    /* One column as wide as the box, not as wide as a row's three sets. */
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-16);
    width: 100%;
    max-width: 2400px;
    margin-block: calc(var(--space-4) * -1);
    user-select: none;
}

/* Not inherited, so a change restyles only the track. */
@property --progress {
    syntax: '<number>';
    inherits: false;
    initial-value: 0;
}

/* The track holds the chips three times. --progress from 0 to 1 slides it by one set,
   then it starts over. main.ts moves it. */
.row {
    overflow: clip;
    /* Room for the focus ring, which is 4px outside the chip. */
    padding-block: var(--space-4);
}

.track {
    --copies: 3;
    display: flex;
    width: max-content;
    transform: translateX(calc(var(--progress) * -100% / var(--copies)));
    will-change: transform;
}

.row--right {
    --direction: -1;
}

/* Where each row starts, from 0 to 1. */
.row--1 .track {
    --progress: 0.22;
}

.row--2 .track {
    --progress: 0.93;
}

.row--3 .track {
    --progress: 0.29;
}

.set {
    display: flex;
    gap: var(--space-16);
    margin: 0;
    padding: 0 var(--space-16) 0 0;
    list-style: none;
}

/* Each chip sets --chip, and hover darkens it. The icon is white like the text through
   current-color, and its placeholder through the filter. */
.chip {
    --chip-fill: var(--chip);
    --icon-filter: var(--filter-ink-inverse);

    display: flex;
    align-items: center;
    gap: var(--space-8);
    padding: var(--space-8) var(--space-16);
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--chip-fill);
    color: var(--ink-inverse);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
}

/* Only under a mouse: on a touch screen :hover stays on after the tap. */
@media (hover: hover) {
    .chip:hover {
        --chip-fill: color-mix(in oklab, var(--chip) 86%, black);
    }
}

.chip--signal {
    --chip: var(--brand-500);
}

.chip--salvia {
    --chip: var(--salvia);
}

.chip--yamabuki {
    --chip: var(--yamabuki);
}

.chip--lilac {
    --chip: var(--lilac);
}

.chip--cinnamon {
    --chip: var(--cinnamon);
}

.chip--moss {
    --chip: var(--moss);
}

/* The ends of the rows fade into the page. */
.marquee::before,
.marquee::after {
    content: '';
    position: absolute;
    inset: 0 auto;
    z-index: 1;
    width: clamp(var(--space-48), 11vw, 160px);
    pointer-events: none;
}

.marquee::before {
    left: 0;
    background: linear-gradient(to right, var(--surface), transparent);
}

.marquee::after {
    right: 0;
    background: linear-gradient(to left, var(--surface), transparent);
}

.cta {
    padding: var(--space-8) var(--space-12);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-weight: 500;
    cursor: pointer;
}

@media (hover: hover) {
    .cta:hover {
        background: var(--surface-muted);
    }
}
index.html 1370 lines
html
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>Categories section</title>
        <link rel="stylesheet" href="./categories-section.css" />
        <script type="module" src="./main.ts"></script>
    </head>
    <body>
        <main class="demo">
            <header class="heading">
                <h2 class="heading__title">Learn anything, from anyone</h2>
                <p class="heading__text">
                    Thousands of hands-on courses taught by people who actually do it.
                </p>
            </header>

            <section class="marquee" aria-label="Course categories">
                <!-- target points each icon at its chip, so the whole chip is the hover area. The
                     track holds the set three times. The copies are hidden from screen readers and
                     their chips have tabindex="-1", so Tab stops once at each chip. -->
                <div class="row row--1">
                    <div class="track">
                        <ul class="set" aria-label="Creative skills">
                            <li>
                                <button class="chip chip--signal" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-61-camera.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-61-camera.svg" />
                                    </lord-icon>
                                    photography
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4239-video-camera.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4239-video-camera.svg"
                                        />
                                    </lord-icon>
                                    video creation
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-12-layers.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-12-layers.svg" />
                                    </lord-icon>
                                    graphic design
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-1388-grid-bento.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-1388-grid-bento.svg" />
                                    </lord-icon>
                                    ux design
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-35-pencil.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-35-pencil.svg" />
                                    </lord-icon>
                                    drawing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-54-image-mountain.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-54-image-mountain.svg"
                                        />
                                    </lord-icon>
                                    photo editing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-56-file-text.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-56-file-text.svg" />
                                    </lord-icon>
                                    copywriting
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-362-article.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-362-article.svg" />
                                    </lord-icon>
                                    blogging
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-188-microphone.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-188-microphone.svg" />
                                    </lord-icon>
                                    podcasting
                                </button>
                            </li>
                        </ul>
                        <ul class="set" aria-hidden="true">
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-61-camera.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-61-camera.svg" />
                                    </lord-icon>
                                    photography
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4239-video-camera.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4239-video-camera.svg"
                                        />
                                    </lord-icon>
                                    video creation
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-12-layers.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-12-layers.svg" />
                                    </lord-icon>
                                    graphic design
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-1388-grid-bento.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-1388-grid-bento.svg" />
                                    </lord-icon>
                                    ux design
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-35-pencil.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-35-pencil.svg" />
                                    </lord-icon>
                                    drawing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-54-image-mountain.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-54-image-mountain.svg"
                                        />
                                    </lord-icon>
                                    photo editing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-56-file-text.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-56-file-text.svg" />
                                    </lord-icon>
                                    copywriting
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-362-article.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-362-article.svg" />
                                    </lord-icon>
                                    blogging
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-188-microphone.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-188-microphone.svg" />
                                    </lord-icon>
                                    podcasting
                                </button>
                            </li>
                        </ul>
                        <ul class="set" aria-hidden="true">
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-61-camera.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-61-camera.svg" />
                                    </lord-icon>
                                    photography
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4239-video-camera.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4239-video-camera.svg"
                                        />
                                    </lord-icon>
                                    video creation
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-12-layers.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-12-layers.svg" />
                                    </lord-icon>
                                    graphic design
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-1388-grid-bento.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-1388-grid-bento.svg" />
                                    </lord-icon>
                                    ux design
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-35-pencil.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-35-pencil.svg" />
                                    </lord-icon>
                                    drawing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-54-image-mountain.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-54-image-mountain.svg"
                                        />
                                    </lord-icon>
                                    photo editing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-56-file-text.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-56-file-text.svg" />
                                    </lord-icon>
                                    copywriting
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-362-article.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-362-article.svg" />
                                    </lord-icon>
                                    blogging
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-188-microphone.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-188-microphone.svg" />
                                    </lord-icon>
                                    podcasting
                                </button>
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="row row--2 row--right">
                    <div class="track">
                        <ul class="set" aria-label="Tech and money">
                            <li>
                                <button class="chip chip--lilac" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-369-code.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-369-code.svg" />
                                    </lord-icon>
                                    coding
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-2526-http.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-2526-http.svg" />
                                    </lord-icon>
                                    web development
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-1327-api.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-1327-api.svg" />
                                    </lord-icon>
                                    backend &amp; APIs
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-153-bar-chart-vertical-grow.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-153-bar-chart-vertical-grow.svg"
                                        />
                                    </lord-icon>
                                    data analytics
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4094-arrow-trending-up.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4094-arrow-trending-up.svg"
                                        />
                                    </lord-icon>
                                    investing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-453-piggy-bank.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-453-piggy-bank.svg" />
                                    </lord-icon>
                                    personal finance
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4014-calculator-simple.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4014-calculator-simple.svg"
                                        />
                                    </lord-icon>
                                    accounting
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-146-cart.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-146-cart.svg" />
                                    </lord-icon>
                                    e-commerce
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4073-email.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-4073-email.svg" />
                                    </lord-icon>
                                    email marketing
                                </button>
                            </li>
                        </ul>
                        <ul class="set" aria-hidden="true">
                            <li>
                                <button class="chip chip--lilac" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-369-code.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-369-code.svg" />
                                    </lord-icon>
                                    coding
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-2526-http.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-2526-http.svg" />
                                    </lord-icon>
                                    web development
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-1327-api.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-1327-api.svg" />
                                    </lord-icon>
                                    backend &amp; APIs
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-153-bar-chart-vertical-grow.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-153-bar-chart-vertical-grow.svg"
                                        />
                                    </lord-icon>
                                    data analytics
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4094-arrow-trending-up.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4094-arrow-trending-up.svg"
                                        />
                                    </lord-icon>
                                    investing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-453-piggy-bank.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-453-piggy-bank.svg" />
                                    </lord-icon>
                                    personal finance
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4014-calculator-simple.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4014-calculator-simple.svg"
                                        />
                                    </lord-icon>
                                    accounting
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-146-cart.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-146-cart.svg" />
                                    </lord-icon>
                                    e-commerce
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4073-email.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-4073-email.svg" />
                                    </lord-icon>
                                    email marketing
                                </button>
                            </li>
                        </ul>
                        <ul class="set" aria-hidden="true">
                            <li>
                                <button class="chip chip--lilac" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-369-code.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-369-code.svg" />
                                    </lord-icon>
                                    coding
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-2526-http.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-2526-http.svg" />
                                    </lord-icon>
                                    web development
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-1327-api.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-1327-api.svg" />
                                    </lord-icon>
                                    backend &amp; APIs
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-153-bar-chart-vertical-grow.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-153-bar-chart-vertical-grow.svg"
                                        />
                                    </lord-icon>
                                    data analytics
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4094-arrow-trending-up.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4094-arrow-trending-up.svg"
                                        />
                                    </lord-icon>
                                    investing
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-453-piggy-bank.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-453-piggy-bank.svg" />
                                    </lord-icon>
                                    personal finance
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4014-calculator-simple.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-4014-calculator-simple.svg"
                                        />
                                    </lord-icon>
                                    accounting
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-146-cart.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-146-cart.svg" />
                                    </lord-icon>
                                    e-commerce
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4073-email.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-4073-email.svg" />
                                    </lord-icon>
                                    email marketing
                                </button>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="row row--3">
                    <div class="track">
                        <ul class="set" aria-label="Life and leisure">
                            <li>
                                <button class="chip chip--signal" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-27-globe.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-27-globe.svg" />
                                    </lord-icon>
                                    languages
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-18-location-pin.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-18-location-pin.svg" />
                                    </lord-icon>
                                    travel
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-13-pizza-slice.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-13-pizza-slice.svg" />
                                    </lord-icon>
                                    cooking
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-667-person-cycling.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-667-person-cycling.svg"
                                        />
                                    </lord-icon>
                                    cycling
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-514-swimming-pool.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-514-swimming-pool.svg"
                                        />
                                    </lord-icon>
                                    swimming
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-63-home.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-63-home.svg" />
                                    </lord-icon>
                                    home &amp; interior
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-448-pet-print.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-448-pet-print.svg" />
                                    </lord-icon>
                                    pet care
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4483-dice-one.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-4483-dice-one.svg" />
                                    </lord-icon>
                                    board games
                                </button>
                            </li>
                        </ul>
                        <ul class="set" aria-hidden="true">
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-27-globe.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-27-globe.svg" />
                                    </lord-icon>
                                    languages
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-18-location-pin.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-18-location-pin.svg" />
                                    </lord-icon>
                                    travel
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-13-pizza-slice.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-13-pizza-slice.svg" />
                                    </lord-icon>
                                    cooking
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-667-person-cycling.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-667-person-cycling.svg"
                                        />
                                    </lord-icon>
                                    cycling
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-514-swimming-pool.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-514-swimming-pool.svg"
                                        />
                                    </lord-icon>
                                    swimming
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-63-home.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-63-home.svg" />
                                    </lord-icon>
                                    home &amp; interior
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-448-pet-print.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-448-pet-print.svg" />
                                    </lord-icon>
                                    pet care
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4483-dice-one.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-4483-dice-one.svg" />
                                    </lord-icon>
                                    board games
                                </button>
                            </li>
                        </ul>
                        <ul class="set" aria-hidden="true">
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-27-globe.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-27-globe.svg" />
                                    </lord-icon>
                                    languages
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-18-location-pin.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-18-location-pin.svg" />
                                    </lord-icon>
                                    travel
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--yamabuki" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-13-pizza-slice.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-13-pizza-slice.svg" />
                                    </lord-icon>
                                    cooking
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--lilac" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-667-person-cycling.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-667-person-cycling.svg"
                                        />
                                    </lord-icon>
                                    cycling
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--cinnamon" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-514-swimming-pool.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img
                                            alt=""
                                            src="icons/system-solid-514-swimming-pool.svg"
                                        />
                                    </lord-icon>
                                    swimming
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--moss" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-63-home.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-63-home.svg" />
                                    </lord-icon>
                                    home &amp; interior
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--signal" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-448-pet-print.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-448-pet-print.svg" />
                                    </lord-icon>
                                    pet care
                                </button>
                            </li>
                            <li>
                                <button class="chip chip--salvia" type="button" tabindex="-1">
                                    <lord-icon
                                        class="chip__icon"
                                        current-color
                                        src="icons/system-solid-4483-dice-one.json"
                                        loading="interaction"
                                        trigger="hover"
                                        target=".chip"
                                        aria-hidden="true"
                                    >
                                        <img alt="" src="icons/system-solid-4483-dice-one.svg" />
                                    </lord-icon>
                                    board games
                                </button>
                            </li>
                        </ul>
                    </div>
                </div>
            </section>

            <button class="cta" type="button">Browse all courses</button>
        </main>
    </body>
</html>
main.ts 9 lines
import { defineElement } from '@lordicon/element';

// Registers <lord-icon> with its built-in triggers.
defineElement();

import { marquee } from '@shared/motion/marquee.ts';

// Scrolls the rows. A row stops under the pointer, so a chip can be clicked.
marquee(document.querySelectorAll('.row'));
What it imports 6 shared files
shared/motion/marquee.ts 171 lines
/**
 * Rows that scroll without end. A row slows to a stop while the pointer or keyboard focus is
 * on it, so its items can be clicked, and then picks up again. An item that keyboard focus
 * lands on out of view slides into view.
 *
 * Each row's first child is its track. The track's transform reads `--progress`, where 0 to 1
 * is one round, and this module changes `--progress` once a frame. From the CSS it reads
 * `--progress` (where the row starts), `--copies` (how many times the track holds its items)
 * and `--direction` (-1 runs the row the other way). With reduced motion the rows stand still.
 *
 *   marquee(document.querySelectorAll('.row'));
 */
import { prefersReducedMotion } from './reduced-motion.ts';

export type MarqueeOptions = {
    /** Milliseconds per round at full speed. */
    round?: number;
    /** Milliseconds from standing still to full speed when the page loads. */
    start?: number;
    /** Milliseconds from full speed to a stop. */
    stop?: number;
    /** Milliseconds from a stop back to full speed. */
    resume?: number;
};

type Easing = (p: number) => number;

/** Fast start, slow end. */
export const easeOut: Easing = (p) => 1 - (1 - p) ** 3;

/** Slow start, slow end. */
export const easeInOut: Easing = (p) => (p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2);

/** A slower rate counts as stopped: under a pixel in ten seconds. */
const MIN_RATE = 0.005;

/** The most time one frame may move a row, so a tab brought back does not jump ahead. */
const MAX_STEP = 100;

/** Milliseconds a row takes to slide a focused item into view. */
const SEEK = 400;

const wrap = (n: number) => n - Math.floor(n);

/**
 * The rate part way from `from` to `to`. `progress` is kept within 0 and 1, because a frame
 * can carry a time from just before the change began.
 */
export function rateAt(from: number, to: number, progress: number, easing: Easing): number {
    const rate = from + (to - from) * easing(Math.min(Math.max(progress, 0), 1));
    return rate < MIN_RATE ? 0 : rate;
}

/** Where a row is `elapsed` ms later, wrapped into 0–1. */
export function advance(progress: number, elapsed: number, speed: number, round: number): number {
    return wrap(progress + (speed * elapsed) / round);
}

type Row = {
    track: HTMLElement;
    progress: number;
    direction: number;
    rate: number;
    /** The change of rate under way: stopping, starting, or none. */
    speed: { from: number; to: number; begin: number; duration: number; easing: Easing };
    /** The slide to a focused item, while there is one. */
    seek: { from: number; by: number; to: number; begin: number } | null;
};

export function marquee(
    elements: Iterable<Element>,
    { round = 60_000, start = 1600, stop = 700, resume = 1000 }: MarqueeOptions = {},
): void {
    const still = prefersReducedMotion();
    const seekTime = still ? 0 : SEEK;
    const rows: Row[] = [];

    for (const element of elements) {
        const track = element.firstElementChild;
        if (!(track instanceof HTMLElement)) continue;
        const style = getComputedStyle(track);
        const copies = Number(style.getPropertyValue('--copies')) || 1;
        const row: Row = {
            track,
            progress: wrap(Number(style.getPropertyValue('--progress')) || 0),
            direction: Number(style.getPropertyValue('--direction')) || 1,
            rate: 0,
            speed: {
                from: 0,
                to: still ? 0 : 1,
                begin: performance.now(),
                duration: start,
                easing: easeInOut,
            },
            seek: null,
        };
        rows.push(row);

        let hovered = false;
        let focused = false;
        const retarget = (to: number, duration: number, easing: Easing) => {
            row.speed = { from: row.rate, to, begin: performance.now(), duration, easing };
        };
        const settle = () =>
            hovered || focused || still
                ? retarget(0, stop, easeOut)
                : retarget(1, resume, easeInOut);

        // Slides the row the short way round until `target` is centred, or as near as it can
        // get. Nothing happens if `target` is in view.
        const reveal = (target: Element) => {
            const area = element.getBoundingClientRect();
            const box = target.getBoundingClientRect();
            if (box.left >= area.left && box.right <= area.right) return;
            const offset = box.left - track.getBoundingClientRect().left;
            const goal =
                Math.max(0, offset - (area.width - box.width) / 2) / (track.offsetWidth / copies);
            const to = wrap(goal);
            const by = to - row.progress;
            row.seek = {
                from: row.progress,
                by: by - Math.round(by),
                to,
                begin: performance.now(),
            };
            // Stand still after the slide, or the row would drift off the item.
            row.rate = 0;
            row.speed = { ...row.speed, from: 0, to: 0 };
        };

        // Touch has no hover, so a tap does not stop the row.
        element.addEventListener('pointerenter', (event) => {
            hovered = (event as PointerEvent).pointerType !== 'touch';
            settle();
        });
        element.addEventListener('pointerleave', () => ((hovered = false), settle()));
        element.addEventListener('pointercancel', () => ((hovered = false), settle()));
        element.addEventListener('focusin', (event) => {
            // A click focuses a chip too. Only keyboard focus holds the row.
            const target = event.target as Element;
            focused = target.matches(':focus-visible');
            settle();
            if (focused) reveal(target);
        });
        element.addEventListener('focusout', () => ((focused = false), settle()));
    }

    // One loop moves every row. A row that is not moving is not written to.
    let last = performance.now();
    const frame = (now: number) => {
        const elapsed = Math.min(Math.max(now - last, 0), MAX_STEP);
        last = now;
        for (const row of rows) {
            const { from, to, begin, duration, easing } = row.speed;
            row.rate = rateAt(from, to, (now - begin) / duration, easing);
            if (row.seek) {
                const p = seekTime
                    ? Math.min(Math.max((now - row.seek.begin) / seekTime, 0), 1)
                    : 1;
                row.progress =
                    p < 1 ? wrap(row.seek.from + row.seek.by * easeInOut(p)) : row.seek.to;
                if (p === 1) row.seek = null;
            } else if (row.rate) {
                row.progress = advance(row.progress, elapsed, row.direction * row.rate, round);
            } else continue;
            row.track.style.setProperty('--progress', row.progress.toFixed(6));
        }
        requestAnimationFrame(frame);
    };
    if (rows.length) requestAnimationFrame(frame);
}
shared/motion/reduced-motion.ts 7 lines
/**
 * Whether the viewer asked for less motion. Script-driven animations have to check this
 * themselves; a media query only switches off CSS ones.
 */
export function prefersReducedMotion(): boolean {
    return globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
}
shared/styles/base.css 117 lines
css
/*
 * Fonts, reset and default typography. Nothing control-specific: every demo styles its
 * own control. Only the UI face is here; Inter and the mono face are the portal's.
 */
@font-face {
    font-family: 'Figtree';
    font-style: normal;
    font-weight: 300 900;
    font-display: swap;
    src: url('../fonts/figtree-latin.woff2') format('woff2');
    unicode-range:
        U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
        U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Figtree';
    font-style: normal;
    font-weight: 300 900;
    font-display: swap;
    src: url('../fonts/figtree-latin-ext.woff2') format('woff2');
    unicode-range:
        U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
        U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113,
        U+2C60-2C7F, U+A720-A7FF;
}

/* Arial with Figtree's measurements, for the moment before Figtree arrives, so the text does
   not move when it does. Measured on Figtree at 400 and 500. */
@font-face {
    font-family: 'Figtree fallback';
    src: local('Arial'), local('Liberation Sans');
    size-adjust: 100.3%;
    ascent-override: 94.7%;
    descent-override: 24.9%;
    line-gap-override: 0%;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* An author `display` on a component would beat the UA rule for [hidden], and then
   `el.hidden = true` would stop working. Settled once here. */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--surface);
    color: var(--ink);
    --icon-filter: var(--filter-ink);
    font-family: var(--font-ui);
    font-size: var(--text-base);
    line-height: var(--leading-base);
    -webkit-font-smoothing: antialiased;
    /* No grey flash on tap. Controls show their own :active and :focus-visible. */
    -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea,
select {
    font: inherit;
    color: inherit;
}

/* A second click on a button would otherwise select its label. */
button {
    -webkit-user-select: none;
    user-select: none;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/*
 * In the accessibility tree but not on screen: labels and legends that the visual design
 * has no room for. Clipped rather than `display: none`, which would remove it from the
 * tree too, and it also hides live radio inputs that must stay reachable by keyboard.
 */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/*
 * Until the script defines <lord-icon> it is an unknown inline element with no size. These
 * rules give it the box it will have, so nothing moves when it is defined.
 */
lord-icon {
    display: inline-block;
    width: var(--icon-size-32);
    height: var(--icon-size-32);
}

/* A placeholder inside the icon fills it until the icon is ready. */
lord-icon:not(:defined) > img {
    display: block;
    width: 100%;
    height: 100%;
}

/* Placeholders are black. Set --icon-filter wherever an icon's colour is set. */
lord-icon > img {
    filter: var(--icon-filter);
}
shared/styles/index.css 4 lines
css
/* The one stylesheet a demo imports. */
@import './palette.css';
@import './tokens.css';
@import './base.css';
shared/styles/palette.css 87 lines
css
/*
 * Generated from the Figma token export.
 * Raw values only — roles live in tokens.css. Edit the Figma variables, not this file.
 */
:root {
    /* color/ink */
    --gray-0: #FFFFFF;
    --gray-50: #F7F8FA;
    --gray-100: #EEF0F3;
    --gray-200: #DEE1E6;
    --gray-300: #C3C7D0;
    --gray-400: #9BA1AD;
    --gray-500: #767C89;
    --gray-600: #565C68;
    --gray-700: #3D414B;
    --gray-800: #282B33;
    --gray-900: #16181D;
    --gray-950: #0A0B0E;

    /* color/signal */
    --brand-100: #FFEEE9;
    --brand-200: #FFD7CA;
    --brand-300: #FFB199;
    --brand-400: #FF7D5C;
    --brand-500: #FF5A36;
    --brand-600: #E8431F;
    --brand-700: #C2340F;

    /* color/success */
    --green-100: #EDF9F1;
    --green-300: #A7D9BC;
    --green-700: #15803D;

    /* color/error */
    --red-100: #FDECEC;
    --red-300: #F5B5B5;
    --red-700: #DC2626;

    /* typography/font */
    --font-ui-name: 'Figtree';
    --font-mono-name: 'JetBrains Mono';

    /* typography/size */
    --text-xs: 12px;
    --text-sm: 14px;
    --text-base: 16px;
    --text-lg: 20px;
    --text-xl: 24px;
    --text-2xl: 32px;
    --text-3xl: 40px;

    /* typography/lineHeight */
    --leading-xs: 16px;
    --leading-sm: 20px;
    --leading-base: 24px;
    --leading-lg: 28px;
    --leading-xl: 32px;
    --leading-2xl: 40px;
    --leading-3xl: 48px;

    /* spacing (named after the value, the Figma scale is non-linear) */
    --space-4: 4px;
    --space-8: 8px;
    --space-12: 12px;
    --space-16: 16px;
    --space-24: 24px;
    --space-32: 32px;
    --space-48: 48px;
    --space-64: 64px;
    --space-96: 96px;

    /* size/icon */
    --icon-size-16: 16px;
    --icon-size-20: 20px;
    --icon-size-24: 24px;
    --icon-size-32: 32px;
    --icon-size-40: 40px;
    --icon-size-48: 48px;
    --icon-size-64: 64px;
    --icon-size-96: 96px;

    /* radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-pill: 9999px;
}
shared/styles/tokens.css 93 lines
css
/*
 * Design tokens by role. Raw values come from palette.css (generated); which grey is a
 * border and which is muted text is decided here, and so would a dark mode be.
 */
:root {
    /* Text. `--ink*` is always a colour; `--text-*` is always a size. */
    --ink: var(--gray-950);
    /* Text that reads as done or in progress, a step lighter than a heading. */
    --ink-strong: var(--gray-800);
    /* Body copy: a step down from --ink. */
    --ink-soft: var(--gray-600);
    --ink-muted: var(--gray-500);
    --ink-subtle: var(--gray-400);
    /* What has not started yet. */
    --ink-faint: var(--gray-300);
    --ink-inverse: var(--gray-0);

    /* Backgrounds */
    --surface: var(--gray-0);
    --surface-muted: var(--gray-50);
    /* A well inside a surface: the filled shape a single icon sits in. */
    --surface-sunken: var(--gray-100);

    /* Outlines */
    --border: var(--gray-200);
    /* The edge of a box that already has a fill, such as an input. */
    --border-soft: var(--gray-100);
    --border-strong: var(--gray-300);
    --border-accent: var(--brand-400);

    /* Brand accent */
    --accent: var(--brand-500);
    --accent-strong: var(--brand-600);
    --accent-surface: var(--brand-100);
    /* The outline of a tinted box, or a small shape on one. */
    --accent-border: var(--brand-300);
    /* Text or a mark on either of the above. */
    --accent-ink: var(--brand-700);

    /* Status. Warning rides the brand ramp — that is what the designs use. */
    --success: var(--green-700);
    --success-surface: var(--green-100);
    --success-border: var(--green-300);

    --warning: var(--brand-500);
    --warning-surface: var(--brand-100);
    --warning-border: var(--brand-300);

    --danger: var(--red-700);
    --danger-surface: var(--red-100);
    --danger-border: var(--red-300);

    /* Icons. Fed straight into --lord-icon-* by the demos. */
    --icon-color: var(--gray-950);
    --icon-accent: var(--brand-500);

    /* Icon placeholders are black SVGs. Each filter turns black into the colour of the same
       name. Made with a CSS filter generator: make a new one when its colour changes. */
    --filter-ink: invert(2%) sepia(4%) saturate(4817%) hue-rotate(193deg) brightness(114%)
        contrast(96%);
    --filter-ink-soft: invert(33%) sepia(18%) saturate(323%) hue-rotate(182deg) brightness(100%)
        contrast(90%);
    --filter-ink-muted: invert(55%) sepia(23%) saturate(191%) hue-rotate(181deg) brightness(84%)
        contrast(89%);
    --filter-ink-subtle: invert(70%) sepia(11%) saturate(284%) hue-rotate(181deg) brightness(91%)
        contrast(86%);
    --filter-ink-faint: invert(76%) sepia(17%) saturate(99%) hue-rotate(184deg) brightness(99%)
        contrast(100%);
    --filter-ink-inverse: invert(100%);
    --filter-accent: invert(49%) sepia(65%) saturate(3508%) hue-rotate(337deg) brightness(106%)
        contrast(113%);
    --filter-accent-strong: invert(29%) sepia(85%) saturate(1790%) hue-rotate(350deg)
        brightness(94%) contrast(93%);
    --filter-success: invert(38%) sepia(22%) saturate(2045%) hue-rotate(94deg) brightness(92%)
        contrast(84%);
    --filter-warning: var(--filter-accent);
    --filter-danger: invert(48%) sepia(74%) saturate(7139%) hue-rotate(343deg) brightness(84%)
        contrast(105%);

    /* Type stacks. The families themselves are in palette.css. */
    --font-ui:
        var(--font-ui-name), 'Figtree fallback', -apple-system, BlinkMacSystemFont, 'Segoe UI',
        Roboto, sans-serif;
    --font-mono: var(--font-mono-name), ui-monospace, SFMono-Regular, Menlo, monospace;

    /* Side padding of a page. The portal uses the same value, so demo and text line up. */
    --gutter: clamp(var(--space-16), 5vw, var(--space-48));

    /* A card's halo: no offset, so it reads as lift rather than as a light source. */
    --shadow-sm: 0 0 7.5px color-mix(in srgb, var(--gray-400) 20%, transparent);
    /* The same halo under a brand-coloured element. */
    --shadow-accent: 0 0 7.5px color-mix(in srgb, var(--accent-strong) 40%, transparent);
}

Icons

Hover a row to play its icon. A state marked default plays without a state attribute. The icons are under the Lordicon License Terms, not the MIT licence of the code.

Preview Lordicon icon Animation state
system-solid-61-camera
hover-pinch default
system-solid-4239-video-camera
hover-pinch default
system-solid-12-layers
hover-pinch default
system-solid-1388-grid-bento
hover-pinch default
system-solid-35-pencil
hover-pinch default
system-solid-54-image-mountain
hover-pinch default
system-solid-56-file-text
hover-pinch default
system-solid-362-article
hover-pinch default
system-solid-188-microphone
hover-pinch default
system-solid-369-code
hover-pinch default
system-solid-2526-http
hover-pinch default
system-solid-1327-api
hover-pinch default
system-solid-153-bar-chart-vertical-grow
hover-pinch default
system-solid-4094-arrow-trending-up
hover-pinch default
system-solid-453-piggy-bank
hover-pinch default
system-solid-4014-calculator-simple
hover-pinch default
system-solid-146-cart
hover-pinch default
system-solid-4073-email
hover-pinch default
system-solid-27-globe
hover-pinch default
system-solid-18-location-pin
hover-pinch default
system-solid-13-pizza-slice
hover-pinch default
system-solid-667-person-cycling
hover-pinch default
system-solid-514-swimming-pool
hover-pinch default
system-solid-63-home
hover-pinch default
system-solid-448-pet-print
hover-pinch default
system-solid-4483-dice-one
hover-pinch default

When to use the Categories section component

Use it on landing pages for marketplaces, course platforms and stores to show the breadth of what you offer. Three rows scroll endlessly, the middle one in the opposite direction, creating movement without a carousel. Pointing at a row pauses it and plays the chip's icon.

Animated categories section: three rows of scrolling category chips with icons that play on hover

Accessibility

  • Only one copy of each chip is exposed. The looping duplicates are hidden from screen readers and skipped by Tab.
  • A row stops when one of its chips has keyboard focus, and the focused chip scrolls into view.
  • With prefers-reduced-motion, the rows stay still.
  • Chips are native buttons with visible labels.