How to Add 3D Animation to a Website: CSS, Scroll or WebGL | HorizonX
← The Journal

3D Animation

How to Add 3D Animation to a Website: CSS, Scroll or WebGL

Add 3D animation to a website with CSS transforms, scroll-driven CSS or WebGL. Tested code, a decision table, browser support and reduced-motion fallbacks.

HorizonX

HorizonX

·9 min read

How to Add 3D Animation to a Website: CSS, Scroll or WebGL

To add 3D animation to a website, pick the lightest technique that delivers the effect: CSS 3D transforms for tilting cards and flips, scroll-driven CSS for depth that follows the reader, and WebGL (three.js, Spline or model-viewer) for real models and lighting. Every option needs a reduced-motion fallback and a still frame.

Below is working code for each level, a table to choose between them, and a performance and accessibility checklist. If you want finished 3D designs and components instead of starting from zero, browse the HorizonX 3D website design collection.

How to create a 3D animation website: choose the level first

Most "3D websites" mix a little real 3D with a lot of flat layout that moves in perspective. Decide per element, not per site.

Technique Good for Cost Fallback
CSS 3D transforms Card tilt, flips, rings of images, layered depth No library; cheap when you animate only transform and opacity The flat layout
Scroll-driven CSS Elements that rotate or rise in depth as they enter the viewport No JavaScript where supported Content shown without the effect
WebGL (three.js, Spline export) Real models, lighting, materials, shaders A library download and GPU work every frame A poster image
<model-viewer> Product models with orbit controls and AR One web component A poster image
Pre-rendered video Cinematic sequences with no interaction File size and decoding Poster frame plus a pause control

A simple rule: if the visitor never interacts with the 3D object, CSS or a short video is usually enough. Reach for WebGL when lighting, materials or free rotation are the point.

Three steps from a CSS card tilt to a scroll-linked tilt to a WebGL model inside a canvas

Level 1: CSS 3D transforms

CSS can rotate and move elements in three dimensions. Put perspective on a parent to set the viewing distance, then use rotateX(), rotateY() and translateZ() on children. transform-style: preserve-3d keeps nested children in the same 3D space, and backface-visibility: hidden hides the reverse side of a flipped face. MDN's guide to using CSS transforms covers the model, and the perspective reference explains the distance value.

Support is broad. According to MDN's browser compatibility data (checked 2026-10-09), perspective and transform-style work since Chrome 36, Firefox 16 and Safari 9, and the unprefixed backface-visibility since Safari 15.4.

A pointer-tilt card

The card below tilts toward the pointer. CSS owns the transform and the reduced-motion rule; JavaScript only writes two custom properties.

.scene {
  perspective: 900px;
}

.card {
  display: block;
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform 150ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .card {
    transform: none;
    transition: none;
  }
}
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
const MAX_TILT = 10; // degrees

for (const card of document.querySelectorAll('.card')) {
  card.addEventListener('pointermove', (event) => {
    if (reduceMotion.matches || event.pointerType !== 'mouse') return;
    const box = card.getBoundingClientRect();
    const x = (event.clientX - box.left) / box.width - 0.5; // -0.5 to 0.5
    const y = (event.clientY - box.top) / box.height - 0.5;
    card.style.setProperty('--ry', `${x * MAX_TILT * 2}deg`);
    card.style.setProperty('--rx', `${y * -MAX_TILT * 2}deg`);
  });
  card.addEventListener('pointerleave', () => {
    card.style.removeProperty('--rx');
    card.style.removeProperty('--ry');
  });
}

Three details matter. The card is a normal link, so it stays focusable and readable with no script. The script ignores touch and pen input, so it never competes with scrolling on a phone. And the reduced-motion check runs in both CSS and JavaScript, so a user who asked for less motion gets a flat, still card.

A note on flip cards

The common flip card flips on :hover and :focus-within. If the front face contains a link, focusing that link flips the card and turns the focused element away from the user. Flip with a button that toggles a class or aria-pressed, and keep each face's links reachable only while that face is showing.

For an image ring built the same way, see Gallery Ring: pure CSS 3D with no three.js or WebGL, with drag, scroll and auto-rotate, four layouts, and reduced-motion handling.

Level 2: 3D that follows the scroll

CSS scroll-driven animations tie a keyframe animation to an element's progress through the viewport, with no scroll listener. The snippet tilts a block up into place as it enters:

@keyframes tilt-in {
  from {
    opacity: 0;
    transform: perspective(1000px) rotateX(30deg) translateY(3rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .tilt-in {
      animation: tilt-in linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 35%;
    }
  }
}

animation-timeline: view() links progress to the element's visibility, and animation-range: entry 0% cover 35% finishes the motion once a third of the viewport has scrolled past it. Both the @supports test and the reduced-motion query wrap the rule, so browsers without support and users who prefer less motion simply see the content in place. MDN's scroll-driven animations guide explains the timelines.

Browser support matters here. MDN's compatibility data for animation-timeline (checked 2026-10-09) lists Chrome and Edge 115 and Safari 26; Firefox has it only behind a preview flag. If the effect must run in Firefox, or you need pinned sections and scrubbed timelines, use GSAP's ScrollTrigger and keep the same reduced-motion rule.

Scroll Hold is a ready version of this idea: cards rush in, hold at the centre, then fall into depth. You tune hold, tilt, depth and blur in the editor and export a self-contained HTML file.

Level 3: real-time 3D with WebGL

For models, lighting and materials you need WebGL. Three common routes:

  • three.js, MIT licensed (version 0.186.1 on npm on 2026-10-09), when you write the scene in code and want full control. Start at the three.js docs.
  • Spline, when a designer builds the scene visually. Its code export offers vanilla JavaScript, a three.js loader, React, Next.js and react-three-fiber.
  • model-viewer, a web component from Google for displaying interactive 3D models on the web and in AR. It suits product pages that show one model.

WebGL 2 is available in Chrome 56, Firefox 51 and Safari 15 and later (MDN compatibility data, checked 2026-10-09), but a GPU-heavy scene still costs battery on every frame. The most useful habit is to stop rendering when nobody can see the result:

// Assumes an existing three.js setup: renderer, scene, camera and a tick() function
const canvas = renderer.domElement;
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
let onScreen = false;

function updateLoop() {
  const shouldAnimate =
    onScreen && !reduceMotion.matches && document.visibilityState === 'visible';
  renderer.setAnimationLoop(shouldAnimate ? tick : null);
  if (!shouldAnimate) renderer.render(scene, camera); // keep one still frame
}

new IntersectionObserver(([entry]) => {
  onScreen = entry.isIntersecting;
  updateLoop();
}).observe(canvas);

reduceMotion.addEventListener('change', updateLoop);
document.addEventListener('visibilitychange', updateLoop);

The three.js docs recommend setAnimationLoop over a manual requestAnimationFrame loop, and passing null stops it (the renderer calls animation.stop() in the three.js 0.186.1 source). The loop now runs only while the canvas is on screen, the tab is visible and the user has not asked for reduced motion. In every other case one still frame stays on the canvas.

A low-poly rabbit model rotating inside a WebGL canvas, beside the same canvas paused on a single still frame

Crystal Cube is an example of this level as a finished component: a beveled crystal cube with spectral refraction that you rotate by dragging or with the arrow keys, Home restores the view, and automatic rotation respects reduced motion. It needs a browser with WebGL 2, and its HTML export loads a pinned three.js build from esm.sh, so the first load needs a network connection. Plan the static fallback before you embed any WebGL layer; the HorizonX post on shader backgrounds and static fallbacks walks through that for React.

Performance and accessibility checklist

  • Animate transform and opacity. web.dev's animations guide recommends restricting animations to those two properties to keep them on the compositing stage.
  • Respect prefers-reduced-motion in CSS and in JavaScript (supported since Chrome 74, Firefox 63 and Safari 10.1).
  • Anything that moves on its own for more than five seconds needs a way to pause, stop or hide it (WCAG 2.2.2).
  • Motion triggered by interaction should be possible to turn off unless it is essential (WCAG 2.3.3, level AAA).
  • Stop WebGL render loops when the canvas is off screen or the tab is hidden.
  • Ship a poster or still frame, and make sure the page still works if WebGL fails to start.
  • Give every drag interaction a keyboard equivalent.
  • Keep headings and copy in HTML, not painted into a canvas, so they stay searchable and readable by assistive technology.

FAQ

Can you add 3D animation to a website for free?

Yes. CSS 3D transforms and scroll-driven CSS need no library at all, and three.js, the code route to real-time WebGL in this guide, is MIT licensed. Free to use is not the same as free to run, though: a WebGL scene costs GPU work and battery on every frame, so stop the render loop when the canvas is off screen and ship a still frame as the fallback.

How do you make a 3D website interactive?

Match the interaction to the technique. A card that tilts toward the pointer needs only CSS 3D transforms and a few lines of JavaScript, while dragging or orbiting a real model needs WebGL through three.js, a Spline export or model-viewer. Whichever you choose, give every drag interaction a keyboard equivalent, ignore touch input where the effect would fight scrolling, and respect reduced motion in both CSS and JavaScript.

Where can I find 3D animation website templates?

If you want a finished starting point instead of code from scratch, look for components you can tune and export. The HorizonX 3D website design collection groups dimensional designs and components. Two covered in this guide are Crystal Cube, a WebGL 2 crystal you rotate by dragging or with the arrow keys, and Scroll Hold, a scroll-driven card effect that exports a self-contained HTML file. Check each one's fallback before you embed it.

Which website is best for 3D animation?

No single tool wins, because they solve different jobs. Use Spline when a designer owns the scene and wants code export, three.js when developers need full control, model-viewer for a single product model, and plain CSS when the effect is cards, image rings or layered depth. Pick the lightest one that delivers the effect you designed.

To skip the setup, browse dimensional designs and components in the HorizonX 3D website design collection.