Three.js is a JavaScript library for making 3D that runs right in the browser. It's behind a lot of things you've probably clicked around in: product viewers, data you can fly through, browser games, VR scenes, and the compass on my homepage. You don't have to be a graphics programmer to use it, especially if a coding agent is doing the typing. It does help to know the basic pieces, though, so you can ask for the right thing and spot when something's off. Below is how a scene fits together, how to keep it fast, and some sites worth studying.

What Three.js does

Browsers can already draw 3D through WebGL (and now WebGPU), but the raw API is low-level: buffers, shaders, matrices. Three.js wraps it in objects you can reason about, like "a box with a matte green surface, lit from the top left, seen from here."

The key difference from a video or GIF: the scene is drawn live, many times a second. That means it can react to a click, a scroll, the mouse, or your data. If nothing on your page needs to react, a video is simpler.

The six pieces of every scene

PieceWhat it isThink of it as
SceneThe container for everything you want to showThe stage
CameraDecides what part of the scene is visible. PerspectiveCamera takes a field of view, aspect ratio, and near/far limitsWhere the viewer stands
GeometryThe shape: points and faces. BoxGeometry, SphereGeometry, or a model you loadThe skeleton
MaterialHow the surface looks: color, roughness, metalness, textureThe paint
MeshOne geometry plus one material, which you can place, rotate and scaleAn actor on stage
RendererDraws the scene from the camera onto a <canvas>The projector

Two more you'll meet early: lights (most realistic materials, like MeshStandardMaterial, render black without one) and loaders like GLTFLoader, which bring in models made in Blender or another 3D tool as .glb files.

How they work together

Every Three.js page follows the same loop. Here's the official minimal example, a spinning cube:

PROMPT / COPY-PASTE
import * as THREE from 'three';

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setAnimationLoop(animate);
document.body.appendChild(renderer.domElement);

const cube = new THREE.Mesh(
  new THREE.BoxGeometry(1, 1, 1),
  new THREE.MeshBasicMaterial({ color: 0x00ff00 })
);
scene.add(cube);
camera.position.z = 5;

function animate(time) {
  cube.rotation.x = time / 2000;
  cube.rotation.y = time / 1000;
  renderer.render(scene, camera);
}

Read it as three steps:

  1. Build the world. Make meshes from geometry and material, then scene.add() them. Objects can be nested, so moving a parent moves its children (a lid hinged to a box, a planet with its moon).
  2. Point the camera. Everything starts at (0, 0, 0), so the camera moves back to see the cube instead of sitting inside it.
  3. Render in a loop. setAnimationLoop calls animate on every screen refresh. Change positions or rotations there, then render. That's all animation is: small changes, redrawn fast.

Interaction plugs into the same loop. A mouse move or button click updates a value, and the next frame draws it.

Pick your setup

If your site is...UseWhy
Plain HTML or a no-code builderThree.js directlyOne script, no framework needed
React or Next.jsReact Three Fiber (+ Drei for ready-made helpers)Write the scene as components; it creates the scene, camera and renderer for you
A scroll-driven storyThree.js + GSAP ScrollTriggerGSAP ties animation to scroll position
Design-first, little codeSplineBuild visually and embed; less control over custom behavior

React Three Fiber is a React renderer for Three.js, not a replacement. Version matters: R3F v9 pairs with React 19, and v8 with React 18. My site is Next.js, so both the compass and the Skill Machine use R3F v9.

Ship it without slowing your site

These are the settings I'd ask a coding agent for on any small 3D feature. All of them are in my site's components.

  • Load it on the client only. In Next.js, import the scene with dynamic(..., { ssr: false }). There's no GPU on the server.
  • Render on demand. For something that only moves when clicked, R3F's frameloop="demand" draws a frame only when something changes, instead of 60 times a second forever.
  • Cap the pixel ratio. dpr={[1, 1.5]} stops high-density phone screens from rendering three or four times the pixels.
  • Respect reduced motion. Check prefers-reduced-motion and skip straight to the end state.
  • Have a fallback. Some devices can't run WebGL. Show a static version so the content still works without the 3D.
  • Use primitives before models. Boxes and cylinders load instantly. A downloaded model needs compression and can quickly outweigh the rest of your page.

Few triangles doesn't guarantee speed. A heavy material or a full-resolution canvas on a phone can be slower than a detailed model.

Sites worth studying

  • Bruno Simon's portfolio: you drive a little car around a world to find his projects. The source is open (MIT), including how assets go from Blender to the browser. Study it for navigation as play.
  • Realistic water simulation: a pool with ripples, light patterns on the floor and droplets on the camera, built with React Three Fiber and shaders. The builder's breakdown shows how each layer adds one visual cue.
  • 3D Force Graph: a library for networks you can orbit and click. Useful for showing how ideas, tools or people connect. In 3D, nodes can hide behind each other, so use 2D if people need to read the data precisely.
  • Three.js examples: hundreds of official demos, each with source. The fastest way to find "the effect I want" and hand its code to an agent.
  • Awwwards Three.js collection: award-winning sites built with it, for design inspiration.

Your first build

Before you start, ask: would this be easier to understand, explore or remember in 3D than as a normal card or button? If not, skip the 3D.

If yes, start with one small object and one interaction. Paste this into Claude Code or Codex from your project folder:

PROMPT / COPY-PASTE
Add a small interactive 3D element to [page]: a [simple object, e.g. a box, globe, compass] that [interaction, e.g. spins and reveals a link when clicked]. Inspect the project first and use Three.js directly, or React Three Fiber if this is a React/Next.js site. Use simple built-in geometry and my existing colors, no external models. Load it client-side only, render on demand, cap the pixel ratio at 1.5, support prefers-reduced-motion, and show a static fallback if WebGL isn't available. Keep the change isolated, run it locally, and stop.

Then open the Three.js Editor in another tab. Add a box, a light and a camera, and move them around. Ten minutes there makes the code above much easier to read.

Go deeper: Three.js manual · Drei helpers · GSAP ScrollTrigger · What to build with GPT-6 Astra