Skip to content

Sticky scroll steps in HTML and CSS

Text scrolls on the left while a visual stays stuck on the right and changes at each step, using CSS sticky and IntersectionObserver. No dependencies, with a vertical stack as fallback.

Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in HTML and CSS

index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Étapes en défilement collant</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <section class="efst" aria-labelledby="efst-titre" data-efst>
        <header class="efst__head">
script.js
for (const root of document.querySelectorAll("[data-efst]")) {
  const steps = [...root.querySelectorAll("[data-efst-step]")];
  const texts = steps.map((step) => step.querySelector("[data-efst-text]"));
  const nav = root.querySelector("[data-efst-nav]");
  const links = [...nav.querySelectorAll("a")];
  const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");
  // On a very short or heavily zoomed window the sticky panel would hide the text.
  const tall = window.matchMedia("(min-height: 30rem)");
  let observer = null;

  const show = (index) => {
    steps.forEach((step, i) => step.toggleAttribute("data-active", i === index));
style.css
body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  margin: 0;
  min-height: 100vh;
  background: var(--demo-bg);
  color: var(--demo-text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.demo {

Free component: copy it freely, including for commercial projects.

Visual effects components in HTML and CSS
  • Cards that fade in as they enter the screen, one after another in each row, without a line of JavaScript and with a static fallback.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A translucent card with a saturated blur whose sharper edge refracts the colourful shapes drifting behind it, with an opaque fallback when transparency is reduced.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A help block shaped like a conversation: bubbles, three animated typing dots and clickable quick replies that show your answers to frequent questions, frozen under prefers-reduced-motion.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A paragraph whose words turn from grey to full ink, one by one, as the page scrolls, in pure CSS with a plain-text fallback.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Four offset, translucent sine waves gently roll along the bottom of a section, each at its own pace.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component