> ## Documentation Index
> Fetch the complete documentation index at: https://hyperframes.heygen.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Swipe Rail

> A contact circle leads a horizontal card rail through a fast drag, momentum carry, and settled snap to the next card.

export const InstallCommand = ({command}) => {
  const [copied, setCopied] = React.useState(false);
  const copy = async () => {
    try {
      if (navigator.clipboard && window.isSecureContext) {
        await navigator.clipboard.writeText(command);
      } else {
        const previous = document.activeElement;
        const scratch = document.createElement("textarea");
        scratch.value = command;
        scratch.setAttribute("readonly", "");
        scratch.style.position = "fixed";
        scratch.style.opacity = "0";
        document.body.appendChild(scratch);
        scratch.select();
        document.execCommand("copy");
        document.body.removeChild(scratch);
        previous?.focus?.();
      }
      setCopied(true);
      setTimeout(() => setCopied(false), 2000);
    } catch {}
  };
  return <div className="hf-install-command not-prose my-4 flex items-stretch overflow-hidden rounded-xl border border-zinc-200 bg-zinc-50 dark:border-zinc-800 dark:bg-zinc-900">
      <code className="flex-1 overflow-x-auto whitespace-nowrap border-r border-zinc-200 px-4 py-3 font-mono text-sm text-zinc-800 dark:border-zinc-800 dark:text-zinc-100">
        {command}
      </code>
      <button type="button" onClick={copy} data-copied={copied ? "true" : "false"} aria-label={`Copy ${command} to the clipboard`} className="hf-install-copy">
        <svg className="hf-install-copy-clipboard" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 18 18" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
          <path d="M14.25 5.25H7.25C6.14543 5.25 5.25 6.14543 5.25 7.25V14.25C5.25 15.3546 6.14543 16.25 7.25 16.25H14.25C15.3546 16.25 16.25 15.3546 16.25 14.25V7.25C16.25 6.14543 15.3546 5.25 14.25 5.25Z" />
          <path d="M2.80103 11.998L1.77203 5.07397C1.61003 3.98097 2.36403 2.96397 3.45603 2.80197L10.38 1.77297C11.313 1.63397 12.19 2.16297 12.528 3.00097" />
        </svg>
        <svg className="hf-install-copy-check" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 18 18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
          <path d="M2.75 9.5L6.5 13.25L15.25 4.5" />
        </svg>
      </button>
      <span className="hf-install-copy-status" role="status" aria-live="polite">
        {copied ? "Copied" : ""}
      </span>
    </div>;
};

<iframe className="w-full aspect-video rounded-xl border-0 bg-zinc-100 dark:bg-zinc-800" title="swipe-rail preview" loading="lazy" srcDoc={`<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0;height:100%;overflow:hidden;background:transparent}hyperframes-player{display:block;width:100%;height:100%}</style><script src="https://cdn.jsdelivr.net/npm/@hyperframes/player@0.7/dist/hyperframes-player.global.js"><\/script></head><body><script>fetch("/public/catalog/components/swipe-rail.json").then(function(r){return r.json()}).then(function(d){var p=document.createElement("hyperframes-player");p.setAttribute("srcdoc",d.html);p.setAttribute("controls","");p.setAttribute("autoplay","");p.setAttribute("loop","");p.setAttribute("muted","");p.setAttribute("poster","https://static.heygen.ai/hyperframes-oss/docs/images/catalog/components/swipe-rail.png");document.body.appendChild(p)});<\/script></body></html>`} />

## Install

<InstallCommand command="npx hyperframes add swipe-rail" />

That writes one file: `compositions/components/swipe-rail.html`.

## Paste it into your composition

Open `compositions/components/swipe-rail.html` and copy what is inside into your own composition.

A component has no size or duration of its own. It takes both from the composition
you paste it into.

## Variables

Every one of these has a default, so the piece works untouched. Set the ones you
want to change on the element:

| Variable            | Default   | Accepts                   | What it does                                              |
| ------------------- | --------- | ------------------------- | --------------------------------------------------------- |
| `card_count`        | `4`       | 3 to 5, step 1            | Number of cards rendered in the rail.                     |
| `accent`            | `green`   | `green`, `blue`, `violet` | Active color used by the focused card and contact circle. |
| `card_label_prefix` | `Feature` | string                    | Text placed before each card number.                      |

Set them with `data-variable-values` on the element that mounts it. These are the
defaults, so this behaves exactly like the preview above until you change one:

```html wrap theme={null}
<div
  data-composition-id="swipe-rail"
  data-composition-src="compositions/components/swipe-rail.html"
  data-variable-values='{"card_count":4,"accent":"green","card_label_prefix":"Feature"}'
></div>
```

## Source

<Accordion title={`swipe-rail.html`}>
  ```html theme={null}
  <!doctype html>
  <!--
    swipe-rail: HyperFrames video primitive (interaction / gesture / demonstrate)

    Concept: a contact circle leads a horizontal card rail through one swipe.
    The rail follows the drag, carries momentum after release, then snaps the
    next card into focus with a physical settle.

    Variables:
      - card_count (number, 3 to 5, default 4): cards rendered in the rail.
      - accent (enum, default green): active color for focus and contact states.
      - card_label_prefix (string, default "Feature"): label before each card number.

    Envelope (fixed IN and OUT, elastic HOLD only):
      IN_BASE  = 2.20s  rail reveal, touch, drag, release, momentum, snap
      HOLD     = elastic = max(0, D - (IN + OUT)); selected card breathes subtly
      OUT_BASE = 0.45s  clean stage fade and rise
      If D is shorter than IN_BASE + OUT_BASE, IN and OUT compress together.

    Mount contract: the runtime clones only this template. #root fills the host
    box, establishes the container query basis, has no data-width or data-height,
    and registers one paused timeline under the hardcoded swipe-rail id.
  -->
  <html
    lang="en"
    data-composition-id="swipe-rail"
    data-composition-duration="4"
    data-composition-variables='[
      { "id": "card_count", "type": "number", "role": "content", "label": "Card count", "description": "Number of cards rendered in the rail.", "default": 4, "min": 3, "max": 5, "step": 1 },
      { "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Active color used by the focused card and contact circle.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
      { "id": "card_label_prefix", "type": "string", "role": "content", "label": "Card label prefix", "description": "Text placed before each card number.", "default": "Feature" }
    ]'
  >
    <head>
      <meta charset="UTF-8" />
      <title>Swipe Rail</title>
    </head>
    <body>
      <template>
        <div id="root" data-composition-id="swipe-rail" data-duration="4" data-fps="30">
          <style>
            *,
            *::before,
            *::after {
              box-sizing: border-box;
            }

            #root {
              --sr-card-width: 46;
              --sr-card-gap: 4;
              position: absolute;
              inset: 0;
              overflow: hidden;
              container-type: size;
              isolation: isolate;
              color: #f8fafc;
              font-family: Inter, system-ui, sans-serif;
              pointer-events: none;
            }

            .sr-clip {
              position: absolute;
              inset: 0;
              overflow: hidden;
              background: radial-gradient(circle at 50% 45%, #1e293b 0%, #0f172a 72%);
            }

            .sr-stage {
              position: absolute;
              inset: 0;
              overflow: hidden;
              opacity: 0;
            }

            .sr-rail {
              position: absolute;
              left: 50%;
              top: 18cqh;
              display: flex;
              gap: calc(var(--sr-card-gap) * 1cqw);
              height: 64cqh;
              will-change: transform;
            }

            .sr-card {
              position: relative;
              flex: 0 0 calc(var(--sr-card-width) * 1cqw);
              height: 60cqh;
              overflow: hidden;
              padding: 6cqh 4cqw;
              border: 0.16cqmin solid rgba(148, 163, 184, 0.36);
              border-radius: 3.2cqmin;
              background: #f8fafc;
              color: #0f172a;
              box-shadow: 0 3cqh 7cqh rgba(2, 6, 23, 0.34);
              transform-origin: 50% 50%;
              will-change: transform, border-color, box-shadow;
            }

            .sr-card::before {
              content: "";
              position: absolute;
              inset: 0 0 auto;
              height: 1.2cqh;
              background: var(--sr-accent);
              opacity: 0.38;
            }

            .sr-index {
              display: block;
              margin-bottom: 3.2cqh;
              color: var(--sr-accent);
              font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
              font-size: 2.2cqw;
              font-weight: 700;
              letter-spacing: 0.12em;
            }

            .sr-label {
              display: block;
              overflow: hidden;
              font-size: 4.2cqw;
              font-weight: 760;
              line-height: 1.05;
              letter-spacing: -0.04em;
              text-overflow: ellipsis;
              white-space: nowrap;
            }

            .sr-rule {
              display: block;
              width: 72%;
              height: 1.4cqh;
              margin-top: 7cqh;
              border-radius: 1cqh;
              background: #cbd5e1;
              box-shadow:
                0 4cqh 0 #e2e8f0,
                0 8cqh 0 #e2e8f0;
            }

            .sr-contact {
              position: absolute;
              left: 50%;
              top: 57%;
              width: 8cqw;
              aspect-ratio: 1;
              margin: -4cqw 0 0 -4cqw;
              border: 0.32cqmin solid rgba(255, 255, 255, 0.88);
              border-radius: 50%;
              background: color-mix(in srgb, var(--sr-accent) 44%, transparent);
              box-shadow:
                0 0 0 1.2cqmin color-mix(in srgb, var(--sr-accent) 16%, transparent),
                0 1.8cqh 4cqh rgba(2, 6, 23, 0.34);
              opacity: 0;
              will-change: transform, opacity;
            }
          </style>

          <div class="sr-clip clip" data-start="0" data-duration="4" data-track-index="0">
            <div class="sr-stage">
              <div class="sr-rail" role="list" aria-label="Feature cards"></div>
              <div class="sr-contact" aria-hidden="true"></div>
            </div>
          </div>

          <script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
          <script>
            (function () {
              "use strict";

              var root = document.getElementById("root");
              var stage = root.querySelector(".sr-stage");
              var rail = root.querySelector(".sr-rail");
              var contact = root.querySelector(".sr-contact");
              var vars =
                window.__hyperframes && window.__hyperframes.getVariables
                  ? window.__hyperframes.getVariables()
                  : {};

              var countValue = Number(vars.card_count);
              var cardCount = Number.isFinite(countValue)
                ? Math.max(3, Math.min(5, Math.round(countValue)))
                : 4;
              var prefix =
                vars.card_label_prefix == null ? "Feature" : String(vars.card_label_prefix);
              var accentName =
                vars.accent === "blue" || vars.accent === "violet" ? vars.accent : "green";
              var accentColors = {
                green: "var(--brand, #22c55e)",
                blue: "var(--accent, #38bdf8)",
                violet: "var(--accent-2, #a78bfa)",
              };
              root.style.setProperty("--sr-accent", accentColors[accentName]);
              // GSAP interpolates colors numerically, so tween values need the
              // substituted color rather than the var() form.
              var accentColor = getComputedStyle(root).getPropertyValue("--sr-accent").trim();

              for (var index = 0; index < cardCount; index += 1) {
                var card = document.createElement("article");
                card.className = "sr-card";
                card.setAttribute("role", "listitem");

                var indexEl = document.createElement("span");
                indexEl.className = "sr-index";
                indexEl.textContent = String(index + 1).padStart(2, "0");

                var label = document.createElement("span");
                label.className = "sr-label";
                label.textContent = prefix + " " + String(index + 1);

                var rule = document.createElement("span");
                rule.className = "sr-rule";
                rule.setAttribute("aria-hidden", "true");

                card.append(indexEl, label, rule);
                rail.appendChild(card);
              }

              var cards = rail.querySelectorAll(".sr-card");
              var centerIndex = Math.floor((cardCount - 1) / 2);
              var targetIndex = centerIndex + 1;
              var currentCard = cards[centerIndex];
              var targetCard = cards[targetIndex];

              var rootStyle = getComputedStyle(root);
              var cardWidth = parseFloat(rootStyle.getPropertyValue("--sr-card-width"));
              var cardGap = parseFloat(rootStyle.getPropertyValue("--sr-card-gap"));
              var cardStep = cardWidth + cardGap;
              var initialX = -(centerIndex * cardStep + cardWidth / 2);
              var targetX = initialX - cardStep;

              // Fixed gesture and exit phases compress together only for short mounts.
              var IN_BASE = 2.2;
              var OUT_BASE = 0.45;
              var duration = Math.max(0.001, parseFloat(root.dataset.duration || "4"));
              var baseTotal = IN_BASE + OUT_BASE;
              var envelopeScale = duration < baseTotal ? duration / baseTotal : 1;
              var IN = IN_BASE * envelopeScale;
              var OUT = OUT_BASE * envelopeScale;
              var HOLD = Math.max(0, duration - IN - OUT);
              var OUT_START = IN + HOLD;
              var gestureScale = IN / IN_BASE;

              gsap.set(stage, { opacity: 0, y: "1.5cqh" });
              gsap.set(rail, { x: initialX + "cqw" });
              gsap.set(cards, { scale: 0.94, opacity: 0.74 });
              gsap.set(currentCard, {
                scale: 1.02,
                opacity: 1,
                borderColor: accentColor,
              });
              gsap.set(contact, { x: "0cqw", y: "0cqh", scale: 0.86, opacity: 0 });

              var tl = gsap.timeline({ paused: true });

              tl.to(
                stage,
                { opacity: 1, y: "0cqh", duration: 0.32 * gestureScale, ease: "power2.out" },
                0,
              );
              tl.to(
                contact,
                { opacity: 1, scale: 1, duration: 0.18 * gestureScale, ease: "power2.out" },
                0.4 * gestureScale,
              );

              // Fast initial drag decays under friction while the contact leads the rail.
              tl.to(
                contact,
                { x: "-28cqw", duration: 0.62 * gestureScale, ease: "power3.out" },
                0.66 * gestureScale,
              );
              tl.to(
                rail,
                { x: initialX - 23 + "cqw", duration: 0.62 * gestureScale, ease: "power3.out" },
                0.66 * gestureScale,
              );

              var releaseAt = 1.28 * gestureScale;
              tl.to(
                contact,
                {
                  y: "-5cqh",
                  scale: 0.82,
                  opacity: 0,
                  duration: 0.24 * gestureScale,
                  ease: "power2.out",
                },
                releaseAt,
              );
              tl.to(
                rail,
                {
                  x: initialX - 38 + "cqw",
                  duration: 0.28 * gestureScale,
                  ease: "power2.out",
                },
                releaseAt,
              );

              // The momentum handoff resolves into one exact card-width snap.
              tl.to(
                rail,
                { x: targetX + "cqw", duration: 0.64 * gestureScale, ease: "back.out(1.7)" },
                1.56 * gestureScale,
              );
              tl.to(
                currentCard,
                {
                  scale: 0.94,
                  opacity: 0.74,
                  borderColor: "rgba(148, 163, 184, 0.36)",
                  duration: 0.48 * gestureScale,
                  ease: "power2.out",
                },
                1.5 * gestureScale,
              );
              tl.to(
                targetCard,
                {
                  scale: 1.02,
                  opacity: 1,
                  borderColor: accentColor,
                  boxShadow: "0 3cqh 9cqh rgba(2, 6, 23, 0.42)",
                  duration: 0.64 * gestureScale,
                  ease: "back.out(1.7)",
                },
                1.56 * gestureScale,
              );

              if (HOLD > 0.4) {
                var driftHalf = Math.min(0.55, HOLD / 2);
                var driftRepeat = Math.max(0, Math.floor(HOLD / driftHalf) - 1);
                tl.to(
                  targetCard,
                  {
                    y: "-0.7cqh",
                    duration: driftHalf,
                    ease: "sine.inOut",
                    yoyo: true,
                    repeat: driftRepeat,
                  },
                  IN,
                );
              }

              tl.to(stage, { opacity: 0, y: "-1.5cqh", duration: OUT, ease: "power2.in" }, OUT_START);

              tl.seek(0);
              window.__timelines = window.__timelines || {};
              window.__timelines["swipe-rail"] = tl;
            })();
          </script>
        </div>
      </template>
    </body>
  </html>
  ```
</Accordion>

Tagged `motion-primitive` `interaction` `gesture` `swipe` `cards` `rail`.

## Related topics

* [Browse the complete Catalog](/catalog)
* [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
* [Build a richer composition](/go-further)


## Related topics

- [State Chip Rail](/catalog/components/state-chip-rail.md)
- [Touch Indicator](/catalog/components/touch-indicator.md)
- [Captions and talking-head footage](/prompting/captions-and-talking-heads.md)
