Dashboard / CSS / Details

Creating a Directional Scroll-Reveal Grid Without Animation Libraries

Component Architecture CSS Grid + IntersectionObserver Member Source Code

Building a Hardware-Accelerated Scroll-Reveal Grid with Pure CSS & Vanilla JavaScript

A complete line-by-line engineering breakdown of a zero-dependency two-column feature grid featuring directional slide transitions, GPU-composited transforms, and accessible motion fallbacks.

STACK: HTML5 / CSS3 / ES6+ DEPENDENCIES: 0 KB (Vanilla) ACCESSIBILITY: prefers-reduced-motion
JavaScript Developer Writing Modular Grid and Scroll Observer Code
// FIG 1.0 — Modular separation of presentation styles (CSS) and DOM intersection logic (HTML/JS).

Architectural Overview & Separation of Concerns

Modern front-end interfaces rely heavily on subtle spatial choreography to guide user attention without overwhelming the browser's main thread. Rather than importing heavy animation libraries that inflate bundle sizes and trigger expensive layout recalculations, developers can achieve crisp, 60-frames-per-second scroll reveals using native browser APIs.

In this member resource guide, we have decoupled the component into two clean, modular blocks: a standalone CSS Stylesheet responsible for layout geometry, card elevation, and initial off-canvas states, and a semantic HTML5 + Vanilla JavaScript structure powered by the native IntersectionObserver API. Keeping styling rules isolated from markup and behavioral scripts makes the module effortless to maintain, override, or inject into custom templates.

1. Standalone CSS Stylesheet

Copy the complete CSS ruleset below and place it inside your template's stylesheet or within <style> tags in your document head. Every rule is scoped to establish structural symmetry, smooth cubic-bezier easing, and mobile responsiveness.

scroll-reveal-grid.css CSS
<style>
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, sans-serif;
  }

  html,
  body {
    overflow-x: clip;
    background-color: #f8fafc;
    color: #1e293b;
  }

  /* Grid layout aligned with the upper container */
  .grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 0;
  }

  /* Initial box state (dimmed & extending past the upper container edge) */
  .box {
    background-color: #ffffff;
    padding: 40px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    opacity: 0.25;
    transition: transform 0.8s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.8s ease-out;
  }

  /* Deep red / maroon tag matching the upper UI accent */
  .tag {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #801313;
    background-color: #fdf2f2;
    padding: 4px 10px;
    border-radius: 6px;
    margin-bottom: 14px;
  }

  .box h2 {
    font-size: 1.5rem;
    margin-bottom: 14px;
    color: #0f172a;
  }

  .box p {
    line-height: 1.6;
    color: #475569;
  }

  /* Starting position outside the aligned upper container boundary */
  .from-left {
    transform: translateX(-100px);
  }

  .from-right {
    transform: translateX(100px);
  }

  /* Active state on scroll (slides in and aligns with the upper container) */
  .box.visible {
    opacity: 1;
    transform: translateX(0);
  }

  /* Mobile responsive layout */
  @media (max-width: 680px) {
    .grid-container {
      grid-template-columns: 1fr;
      padding: 40px 20px;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .box {
      opacity: 1;
      transform: none;
      transition: none;
    }
  }
</style>

Line-by-Line CSS Engineering Breakdown

  • * { box-sizing: border-box; margin: 0; padding: 0; } Normalizes browser default spacing and ensures that internal card padding (40px) and borders (1px) are calculated inside each element's declared width rather than expanding it outward.
  • html, body { overflow-x: clip; } A critical detail for horizontal slide animations. Because cards start shifted -100px and +100px along the X-axis, they temporarily extend beyond the viewport boundary. Using overflow-x: clip prevents unwanted horizontal scrollbars on mobile and desktop browsers without breaking position: sticky ancestors the way overflow-x: hidden sometimes does.
  • .grid-container { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; } Establishes a symmetrical two-column CSS Grid where each column occupies an equal fraction (1fr) of the available 1200px container, separated by a uniform 24px gutter.
  • .box { opacity: 0.25; transition: transform 0.8s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.8s ease-out; } Instead of hiding elements completely (opacity: 0), setting an initial opacity of 0.25 preserves visual context before scrolling. Animating exclusively transform and opacity delegates rendering directly to the GPU compositor layer, avoiding costly CPU layout reflows. The custom cubic-bezier(0.22, 1, 0.36, 1) curve delivers a rapid initial entry followed by a silky, decelerated settle.
  • .from-left / .from-right & .box.visible Directional modifier classes offset left-column cards by -100px and right-column cards by +100px. Once JavaScript appends the .visible class, transform: translateX(0) glides both columns cleanly into alignment.
  • @media (max-width: 680px) & @media (prefers-reduced-motion: reduce) Below 680px, the grid collapses into a single-column stack (1fr) with 20px horizontal breathing room. Simultaneously, the prefers-reduced-motion media query respects operating-system accessibility settings by disabling motion and rendering all cards at full opacity immediately.

2. Semantic HTML Markup & IntersectionObserver Script

Copy the HTML structure and inline script below and paste it into the body section of your page where you want the feature grid to render. Keep the <script> block positioned immediately after the </section> closing tag so the DOM nodes are already parsed when the script executes.

scroll-reveal-grid.html HTML + JS
<section class="grid-container">
  <article class="box from-left">
    <span class="tag">TEMPLATE</span>
    <h2>Ready-to-Use Page Layouts</h2>
    <p>Start faster with structured dashboard templates and modular UI layouts built to keep interfaces clean and consistent.</p>
  </article>

  <article class="box from-right">
    <span class="tag">CSS</span>
    <h2>Grid, Spacing &amp; Modern Styling</h2>
    <p>Fine-tune grid alignment, spacing, typography, and responsive behavior so every view stays balanced across screen sizes.</p>
  </article>

  <article class="box from-left">
    <span class="tag">JAVASCRIPT</span>
    <h2>Interactions &amp; Scroll Motion</h2>
    <p>Add lightweight dynamic behavior using IntersectionObserver to trigger smooth transitions as sections enter the viewport.</p>
  </article>

  <article class="box from-right">
    <span class="tag">ASSET &amp; DOWNLOAD</span>
    <h2>Resource Packs &amp; Guides</h2>
    <p>Access downloadable files, setup references, and practical resources to support your development workflow.</p>
  </article>
</section>

<script>
  const boxes = document.querySelectorAll(".box");

  const observer = new IntersectionObserver(
    (entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          entry.target.classList.add("visible");
          observer.unobserve(entry.target);
        }
      });
    },
    {
      threshold: 0.2,
    }
  );

  boxes.forEach((box) => observer.observe(box));
</script>

Line-by-Line HTML & JavaScript Breakdown

  • <section class="grid-container"> & <article class="box ..."> Using semantic HTML5 landmarks (<section> for thematic grouping and <article> for self-contained feature cards) improves screen-reader navigation and document outline clarity compared to generic nested <div> wrappers.
  • const boxes = document.querySelectorAll(".box"); Queries the DOM once and stores a static NodeList of every card element carrying the .box selector.
  • new IntersectionObserver((entries) => { ... }, { threshold: 0.2 }) Replaces legacy window.onscroll event listeners—which fire dozens of times per second and block main-thread scrolling—with an asynchronous browser observer. Setting threshold: 0.2 ensures the reveal animation fires only when at least 20% of a card's surface area has entered the visible viewport.
  • entry.target.classList.add("visible"); observer.unobserve(entry.target); Once a card becomes visible, .visible triggers the CSS transition. Immediately calling observer.unobserve(entry.target) detaches the watcher from that specific card, freeing browser memory and ensuring the animation plays once cleanly without flickering when scrolling back up.

Platform Capabilities & Developer Resources

TEMPLATE

Ready-to-Use Page Layouts

Start faster with structured dashboard templates and modular UI layouts built to keep interfaces clean and consistent.

CSS

Grid, Spacing & Modern Styling

Fine-tune grid alignment, spacing, typography, and responsive behavior so every view stays balanced across screen sizes.

JAVASCRIPT

Interactions & Scroll Motion

Add lightweight dynamic behavior using IntersectionObserver to trigger smooth transitions as sections enter the viewport.

ASSET & DOWNLOAD

Resource Packs & Guides

Access downloadable files, setup references, and practical resources to support your development workflow.