Skip to content

Type to search the docs, API, and blog.

↑↓ navigate↵ openesc close
  • Zazz 0.14 alpha

    API

    Reveal

    Scroll-driven reveal animations through `data-reveal` attributes.

    Installation

    Source
    pnpm dlx zazz-ui add reveal
    npx zazz-ui add reveal
    yarn dlx zazz-ui add reveal
    bunx zazz-ui add reveal

    Run zazz-ui init first if the project has no zazz/ folder yet.

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Paint the right theme (background, form controls, scrollbars) before CSS loads -->
    <meta name="color-scheme" content="light dark">
    <!-- Zazz styles: base layers, then reveal in cascade order -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_layers.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_variables.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_shadows.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_breakpoints.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_reset.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_view-transitions.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/reveal/reveal.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-flow.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-grid.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-spacing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-margin.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sizing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-color.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-effects.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-box.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-pseudo.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_defaults.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sr.css">
    <!-- Import map: bare specifiers in Zazz scripts resolve to pinned, SRI-checked files -->
    <script type="importmap">
    {
      "imports": {
        "signal-polyfill": "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js"
      },
      "integrity": {
        "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js": "sha384-0OqM7OXGT6Oz1z98u/geiFn/FUyz4iWexkXHCvbIGXRRDXl6bp6IKc0j78AQ6DEK"
      }
    }
    </script>
    <!-- Polyfill: Interest Invokers (interestfor) — native in Chromium only -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/invokers@2.2.2/dist/esm/production/interest.js" integrity="sha384-hR2BVNtsS7fIIMwOm+f7MY0JZfuByGhQQfevCBB6evFATKzBsTw0JzH/RxD94z2T" crossorigin="anonymous"></script>
    <!-- Zazz behavior: side-effect modules by tag; the rest via module imports -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/dialog-lifecycle.js"></script>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/reveal.js"></script>
    <!-- Theme: apply the persisted (or preferred) scheme before first paint -->
    <script>
      (() => {
        try {
          // A stored choice pins the scheme with data-theme; with no choice the
          // page follows the system scheme.
          const storedTheme = localStorage.getItem("theme");
          if (storedTheme === "dark" || storedTheme === "light") {
            document.documentElement.dataset.theme = storedTheme;
          }
        } catch {
          /* no storage access: follow the system scheme */
        }
      })();
    </script>

    A <head> that loads the base layers and reveal from jsDelivr, pinned to 0.14.2. To load the whole kit in two requests, see the CDN install.

    Examples

    Arrives first Then this one Then the last
    <div
      data-reveal-each="slide-up"
      data-reveal-step="100"
      style="
        --display: grid;
        --grid-cols: 1;
        --grid-cols--sm: 3;
        --gap: 4;
        --w: 100%;
      "
    >
      <ui-card data-card-variant="muted" style="--p: 6">Arrives first</ui-card>
      <ui-card data-card-variant="muted" style="--p: 6">Then this one</ui-card>
      <ui-card data-card-variant="muted" style="--p: 6">Then the last</ui-card>
    </div>
    /**
     * reveal.css — Scroll reveals ([data-reveal] / [data-reveal-each]; the script marks
     *              revealed targets data-reveal-state="in-view")
     *
     * @layer      variables, utilities
     * @requires   _layers.css, _variables.css
     * @uses       prefers-reduced-motion — native media feature
     * @uses       sibling-index(), sibling-count() — native stagger delays (@supports
     *             gated; where unsupported, reveal.js writes a per-child
     *             --ui-reveal-wait instead)
     * @uses       Behaviour requires zazz/scripts/reveal.js (IntersectionObserver)
     * @tokens     --ui-reveal-global-* (@layer variables);
     *             per-instance --ui-reveal-* set from data-* attributes by reveal.js;
     *             --ui-reveal-stagger-base / --ui-reveal-stagger-step on a stagger
     *             group (written by reveal.js from data-reveal-wait / data-reveal-step,
     *             or set in CSS) override the global wait / stagger step
     *
     * A lightweight, configurable animation system for scroll-based reveals. Focuses
     * on viewport entry animations for single elements and direct children of stagger
     * groups. Available animations: slide-up, slide-down, slide-left, slide-right,
     * fade, grow, shrink.
     *
     * @example  Single element
     *   <div data-reveal="slide-up">Content</div>
     *
     * @example  Staggered children — animation applied to each direct child
     *   <div data-reveal-each="fade" data-reveal-step="100">
     *     <div>Item 1</div>
     *     <p>Item 2</p>
     *   </div>
     *
     * Data attributes (on the element with data-reveal or data-reveal-each):
     *   data-reveal="animation-name"        single elements
     *   data-reveal-each="animation-name"   groups; applied to children
     *   data-reveal-duration="300"          ms
     *   data-reveal-wait="0"                ms or a CSS time (0.1s), base delay
     *   data-reveal-step="120"              ms or a CSS time, stagger delay for groups (or set
     *                                       --ui-reveal-stagger-step on the group,
     *                                       --ui-reveal-global-stagger-step on any ancestor)
     *   data-reveal-ease="ease-in-out"
     *   data-reveal-distance="2rem"         translation distance
     *   data-reveal-order="reversed"        stagger order for groups
     *   data-reveal-margin="0px"            IntersectionObserver rootMargin
     *   data-reveal-threshold="0.2"         IntersectionObserver threshold
     *   data-reveal-scale="0.5"             optional initial scale (requires JS mod)
     */
    
    @layer variables {
      :root {
        --ui-reveal-global-duration: 1000ms;
        --ui-reveal-global-timing-function: var(--default-transition-timing-function);
        --ui-reveal-global-wait: 0ms;
        --ui-reveal-global-distance: 2rem;
        --ui-reveal-global-grow: 0.97;
        --ui-reveal-global-shrink: 1.03;
        --ui-reveal-global-stagger-step: 120ms;
      }
    }
    
    @layer ui.utilities {
      @media screen and (prefers-reduced-motion: no-preference) {
        /* Effective values + hidden state, at :where() specificity so the in-view
           final state overrides it. */
        :where(
          [data-reveal]:not([data-gjs-type]),
          [data-reveal-each]:not([data-gjs-type]) > *:not([data-gjs-type])
        ) {
          --ui-reveal-effective-duration: var(--ui-reveal-duration, var(--ui-reveal-global-duration));
          --ui-reveal-effective-ease: var(--ui-reveal-ease, var(--ui-reveal-global-timing-function));
          --ui-reveal-effective-wait: var(--ui-reveal-wait, var(--ui-reveal-global-wait));
          --ui-reveal-effective-distance: var(--ui-reveal-distance, var(--ui-reveal-global-distance));
          will-change: opacity, transform;
          opacity: 0;
        }
    
        /* Deliberately not wrapped in :where(): its (0,1,0) specificity beats bare
           transition utilities in this layer that would reset transition-delay and
           wipe out the per-child stagger. The gjs exclusion uses :not(:where()) to
           add no specificity, so the fade override below still wins on order. */
        [data-reveal]:not(:where([data-gjs-type])),
        [data-reveal-each]:not(:where([data-gjs-type])) > *:not(:where([data-gjs-type])) {
          transition-timing-function: var(--ui-reveal-effective-ease);
          transition-duration: var(--ui-reveal-effective-duration);
          transition-delay: var(--ui-reveal-effective-wait);
          transition-property: opacity, transform;
        }
    
        /* Native stagger: wait = base + step × (index − 1); reversed groups count
           from the end. Base/step come from the group (data-reveal-wait/-step via
           reveal.js, or CSS) or the inherited globals; reveal.js skips its per-child
           --ui-reveal-wait fallback here. */
        @supports (top: calc(sibling-index() * 1px)) {
          [data-reveal-each] > * {
            --ui-reveal-wait: calc(
              var(--ui-reveal-stagger-base, var(--ui-reveal-global-wait)) +
                var(--ui-reveal-stagger-step, var(--ui-reveal-global-stagger-step)) *
                (sibling-index() - 1)
            );
          }
    
          [data-reveal-each][data-reveal-order="reversed"] > * {
            --ui-reveal-wait: calc(
              var(--ui-reveal-stagger-base, var(--ui-reveal-global-wait)) +
                var(--ui-reveal-stagger-step, var(--ui-reveal-global-stagger-step)) *
                (sibling-count() - sibling-index())
            );
          }
        }
    
        [data-reveal="slide-up"]:not(:where([data-reveal-state~="in-view"], [data-gjs-type])),
        [data-reveal-each="slide-up"] > *:not(:where([data-reveal-state~="in-view"], [data-gjs-type])) {
          transform: translateY(var(--ui-reveal-effective-distance));
        }
    
        [data-reveal="slide-down"]:not(:where([data-reveal-state~="in-view"], [data-gjs-type])),
        [data-reveal-each="slide-down"]
          > *:not(:where([data-reveal-state~="in-view"], [data-gjs-type])) {
          transform: translateY(calc(-1 * var(--ui-reveal-effective-distance)));
        }
    
        [data-reveal="slide-left"]:not(:where([data-reveal-state~="in-view"], [data-gjs-type])),
        [data-reveal-each="slide-left"]
          > *:not(:where([data-reveal-state~="in-view"], [data-gjs-type])) {
          transform: translateX(var(--ui-reveal-effective-distance));
        }
    
        [data-reveal="slide-right"]:not(:where([data-reveal-state~="in-view"], [data-gjs-type])),
        [data-reveal-each="slide-right"]
          > *:not(:where([data-reveal-state~="in-view"], [data-gjs-type])) {
          transform: translateX(calc(-1 * var(--ui-reveal-effective-distance)));
        }
    
        [data-reveal="fade"]:not(:where([data-reveal-state~="in-view"], [data-gjs-type])),
        [data-reveal-each="fade"] > *:not(:where([data-reveal-state~="in-view"], [data-gjs-type])) {
          transition-property: opacity;
          transform: none;
        }
    
        [data-reveal="grow"]:not(:where([data-reveal-state~="in-view"], [data-gjs-type])),
        [data-reveal-each="grow"] > *:not(:where([data-reveal-state~="in-view"], [data-gjs-type])) {
          transform: scale(var(--ui-reveal-scale, var(--ui-reveal-global-grow)));
        }
    
        [data-reveal="shrink"]:not(:where([data-reveal-state~="in-view"], [data-gjs-type])),
        [data-reveal-each="shrink"] > *:not(:where([data-reveal-state~="in-view"], [data-gjs-type])) {
          transform: scale(var(--ui-reveal-scale, var(--ui-reveal-global-shrink)));
        }
    
        [data-reveal]:where([data-reveal-state~="in-view"], [data-gjs-type]),
        [data-reveal-each] > *:where([data-reveal-state~="in-view"], [data-gjs-type]) {
          opacity: 1;
          transform: none;
        }
      }
    
      @media (prefers-reduced-motion: reduce) {
        :where([data-reveal], [data-reveal-each] > *) {
          transition: none !important;
          transform: none !important;
          opacity: 1 !important;
          will-change: auto !important;
        }
      }
    }

    Timing

    A reveal runs for 1000ms and moves 2rem by default. In a data-reveal-each group the children start one after another, --ui-reveal-global-stagger-step (120ms) apart. Set that token on any ancestor to retime every group inside it, set --ui-reveal-stagger-step on one group, or put data-reveal-step on the group. data-reveal-step and data-reveal-wait take milliseconds (120) or a CSS time (0.1s).

    Attributes

    reveal attributes
    AttributeKindValuesNotes
    data-reveal-eachPresetfade grow shrink slide-down slide-left slide-right slide-upPreset: a named bundle of values.
    data-reveal-orderPresetreversedPreset: a named bundle of values.
    data-reveal-stateStatein-viewState the kit's script writes; read it in selectors, never author it.
    data-revealConfigfade grow shrink slide-down slide-left slide-right slide-upConfiguration the kit's script reads.
    data-reveal-distanceConfigfree valueConfiguration the kit's script reads.
    data-reveal-durationConfigfree valueConfiguration the kit's script reads.
    data-reveal-easeConfigfree valueConfiguration the kit's script reads.
    data-reveal-marginConfigfree valueConfiguration the kit's script reads.
    data-reveal-scaleConfigfree valueConfiguration the kit's script reads.
    data-reveal-stepConfigfree valueConfiguration the kit's script reads.
    data-reveal-thresholdConfigfree valueConfiguration the kit's script reads.
    data-reveal-waitConfigfree valueConfiguration the kit's script reads.

    Hooks

    Set a hook on :root, on a subtree, or inline on one element. A state hook (--…--hover) themes that state only; the primitive keeps its other states.

    reveal hooks
    HookDefaultState
    --ui-reveal-effective-distancevar(--ui-reveal-distance, var(--ui-reveal-global-distance))—
    --ui-reveal-effective-durationvar(--ui-reveal-duration, var(--ui-reveal-global-duration))—
    --ui-reveal-effective-easevar(--ui-reveal-ease, var(--ui-reveal-global-timing-function))—
    --ui-reveal-effective-waitvar(--ui-reveal-wait, var(--ui-reveal-global-wait))—
    --ui-reveal-global-distance2rem—
    --ui-reveal-global-duration1000ms—
    --ui-reveal-global-grow0.97—
    --ui-reveal-global-shrink1.03—
    --ui-reveal-global-stagger-step120ms—
    --ui-reveal-global-timing-functionvar(--default-transition-timing-function)—
    --ui-reveal-global-wait0ms—
    --ui-reveal-waitcalc( var(--ui-reveal-stagger-base, var(--ui-reveal-global-wait)) + var(--ui-reveal-stagger-step, var(--ui-reveal-global-stagger-step)) * (sibling-index() - 1) )—

    API