TransitionsPremium

Stagger List

A button sends the items of a list out one after another, 80 ms apart, then brings them back in the same order on the next click. A commanded round trip, on your own elements, with the list taken out of keyboard reach while it is out. CSS + 0.9 KB of JavaScript.

CSSJSStaggerList

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Transitions has 52 effects, including 9 free. Explore the category →

3 usage examples

"+" button and its survey actions — a land surveyor's field app — Stagger List example 1

① "+" button and its survey actions — a land surveyor's field app

WhenFacing plot AB 214, the surveyor taps the orange "+" at the bottom of the tablet: "Survey a point", "Photo of a marker", "Measure a distance" and "Voice note" rise one after another above the button. A second tap sends them away.
WhyFour rarely used actions do not deserve four buttons sitting permanently on the plan. The cascade starts from the button, nearest first: the thumb already has the first one under it when the last arrives.
SettingsList closed at the start: stgl-list--out and inert written in the HTML, button at aria-expanded="false". flex-direction: column-reverse on .stgl-list so the first item is the lowest. The items are real <button> elements; the 52 px round button reuses .stgl-toggle. For the capture, the scene presses by itself: out, then back.
What's in the kit — product page of a beginner bookbinding kit — Stagger List example 2

② What's in the kit — product page of a beginner bookbinding kit

WhenA beginner hesitates over a $44 Japanese binding kit and presses "See what's in the kit": in the "In the box" frame, the bone folder, the awl, the needles, the thread, the paper and the boards line up one by one.
WhyThe six rows arrive at reading speed: you count the tools as you would take them out of the box, instead of getting a block all at once.
SettingsSix 44 px rows in a fixed-size frame made for them: the hidden list does not free its place. Full-width button under the price, list closed at the start as in the previous example. With six items, the cascade lasts 900 ms.
Round stops hidden to see the map — a book bus's tablet — Stagger List example 3

③ Round stops hidden to see the map — a book bus's tablet

WhenBetween two villages, the librarian wants to see the road: she taps "Stops on the round" and the five stop cards laid over the map move off toward the edge, first to last, uncovering the route as far as Tourlaine. She taps again, they come back.
WhyThe cards hide half the map. Sending them out in a cascade rather than as one block gives time to see where each one was, hence to find the matching stop on the route.
SettingsList open at the start (original HTML), five 50 px cards on the right side, pill button at the bottom right. The original exit direction, 30 px to the right, fits: the cards leave toward the edge of the screen. No opacity of their own on the list's items, it would override the effect's.

How it works

On load, the script walks the direct children of .stgl-list and writes each one's index into the --stgl-i variable (0, 1, 2…). That is its only part in the cascade: the rest is one CSS rule, transition-delay: calc(var(--stgl-i) * 80ms), which delays each item by 80 ms per index. It does not matter what those children are (rows, cards, buttons) or how many there are.

The .stgl-toggle button adds or removes the .stgl-list--out class. Added, it sends each item 30 px to the right and to opacity 0, in 0.5 s; removed, it brings them back. With five items, the last one leaves at 320 ms and everything is over at 820 ms. Read 400 ms after the click: the first is at 3% opacity, the third at 27%, the fifth still at 94%. The return follows the same order, first one leading, and a click during the movement reverses it from the position reached.

Only opacity and visual position change: the list that is out keeps its place in the page, nothing moves up to fill the gap. So it is made for a panel laid over a background, a menu that fans out or a reserved area, not for a block that would push the following content. The script keeps the state in step: when the list is out, it gets the inert attribute and the button goes to aria-expanded="false".

Accessibility

  • A hidden list that is truly hidden: items at opacity 0 stay reachable by keyboard and read by screen readers. The inert attribute set by the script removes them from both while the list is out. It is understood from Chrome 102, Firefox 112 and Safari 15.5; in an older browser, invisible buttons would remain in the tab order.
  • Reduced motion: no slide and no cascade. The whole list fades out or back as one block, in 150 ms of linear opacity (all five items at the same opacity, between 0.6 and 0.7 after 60 ms, at 0 before 320 ms).
  • Keyboard: the control is a <button> that announces its state through aria-expanded; Enter and Space operate it and focus stays on it. Add aria-controls with your list's id if you want to link them explicitly.
  • Target size: the demo button measures 167 × 26 px. That is above the 24 px minimum, but below the 44 px advised for fingers: increase its padding on mobile.

Browser compatibility

CSS (transition on transform and opacity, a delay computed by calc() from a variable, flexbox with gap) + 0.9 KB of JavaScript (style.setProperty, toggleAttribute). Same cascade read in Chromium 149, Firefox 151 and WebKit 26.5, within a few hundredths of opacity. The animation needs Chrome 84, Firefox 63 or Safari 14.1 (flexbox gap sets those versions); putting the list out of reach also needs inert, hence Chrome 102, Firefox 112 or Safari 15.5.

Chrome 102+✓ Full (measured in Chromium 149)
Firefox 112+✓ Full (measured in Firefox 151)
Safari 15.5+✓ Full (measured in WebKit 26.5)
Edge 102+✓ Full (Chromium engine)
Chrome 84-101, Firefox 63-111, Safari 14.1-15.4✓ Full cascade, hidden list still reachable by keyboard
Mobile iOS 15.5+ / Android Chrome 102+✓ Emulated touch, not checked on a device

Without JavaScript, the list stays on screen and the button does nothing: no content is lost. If the script runs but the --stgl-i variable is not set on an item (added afterwards), that item leaves with no delay, together with the first.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="stgl-root">
  <div class="stgl-list">
    <div class="stgl-item"><span class="stgl-item-dot"></span> …</div>
    <div class="stgl-item"><span class="stgl-item-dot"></span> …</div>
    …
  </div>
  <button class="stgl-toggle" type="button" aria-expanded="true">…</button>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Gap between two items (CSS — 80ms in transition-delay) 80 ms per index 40 ms gives a quick wave, suited to ten items and more; 150 ms clearly separates each row but gets long beyond five.
Direction and distance (CSS — translateX(30px) in .stgl-list--out > *) 30 px to the right translateX(-30px) for a list against the left edge, translateY(12px) for a menu that drops back. Opacity does most of the work: no need to go past 40 px.
Duration of each item (CSS — .5s in both transitions) 0.5 s The total duration is that value plus 80 ms per item after the first: 820 ms for five, 1.2 s for ten. Shorten to 0.3 s for a long list.
Cascade order (CSS — flex-direction on .stgl-list) column: top to bottom column-reverse starts the cascade from the bottom without touching the HTML; row spreads it left to right for a line of tags.
Starting state (HTML — stgl-list--out and inert on the list, aria-expanded="false" on the button) list shown All three written in the HTML, they make it start with the list closed: the first click fans it out. The script does not set them by itself on load.

FAQ

Staggered Reveal plays an entrance, just one, when the block comes on screen: scrolling triggers it, through a CSS animation, and the items rise while growing. Stagger List is a toggle: a button sends the list out, the same one brings it back, as many times as you like, and it also disappears for the keyboard while it is out. The former dresses the appearance of content, the latter is for showing and hiding a menu or a panel.
Not on its own. Indexes are written once, when the script starts; an item inserted later has no --stgl-i variable and so leaves with no delay, with the first one. Give it its index when you add it: element.style.setProperty('--stgl-i', list.children.length - 1).
That is not what this effect does: it touches neither height nor display, to stay smooth and be reversible midway. The hidden list therefore leaves a gap of its size. If the content below must move up, pick Accordion Fold instead, built to open and close a block within the page flow.