Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 39 ยท Getting Started

What Is Three.js?

Learn what Three.js is, how it sits on top of WebGL, what a scene, camera and renderer do, and spin your first 3D cube in the browser.

Three.js is a JavaScript library that draws 3D graphics in the browser. You describe a world made of objects, lights and a camera, and Three.js turns that description into pixels on a <canvas>. It is used for product viewers, games, data visualizations, interactive art, architecture walkthroughs and the animated hero sections you see on modern websites.

Browsers can already draw 3D through an API called WebGL, but WebGL is very low level. Drawing a single lit cube in raw WebGL takes a couple hundred lines: compiling shader programs, uploading buffers, computing matrices by hand. Three.js wraps all of that in friendly objects such as Mesh, PerspectiveCamera and MeshStandardMaterial, so the same cube takes about ten lines.

How the pieces fit together

Every Three.js program has the same skeleton. Learn these four ideas and the rest of the library is variations on them.

The four ingredients

Scene The container for everything you want to draw
Camera The point of view that decides what is visible
Mesh A geometry (shape) plus a material (surface)
Renderer Draws the scene, seen by the camera, onto a canvas

Scene + camera go into renderer.render().

1 / 3

The relationship looks like this:

flowchart LR
  G["Geometry<br/>(shape)"] --> M["Mesh"]
  Mat["Material<br/>(surface)"] --> M
  M --> S["Scene"]
  S --> R["WebGLRenderer"]
  C["Camera"] --> R
  R --> Canvas["canvas element"]

Geometry and material combine into a mesh. The renderer needs a scene and a camera to produce a picture.

Your first scene

The example below is complete. It creates a renderer, a scene, a camera and a cube, then renders one frame. Notice that there is no loop yet, so the cube is still.

A cube, one frame

Read it top to bottom. WebGLRenderer creates a <canvas>, available as renderer.domElement, which you add to the page. Scene is an empty world. PerspectiveCamera(60, aspect, 0.1, 100) is a camera with a 60 degree field of view that sees things between 0.1 and 100 units away. We pushed it back to z = 3 so it is not inside the cube. MeshNormalMaterial colors each face by the direction it points, which needs no lights, so it is perfect for first experiments.

Making it move

A still picture is a render. A moving picture is a render repeated, with a small change between frames. The browser gives us requestAnimationFrame for this, and Three.js wraps it as renderer.setAnimationLoop.

A spinning cube

Each frame adds a little to the cube's rotation (measured in radians) and draws again. Try changing the numbers, swapping BoxGeometry for TorusKnotGeometry(0.6, 0.2, 100, 16), or moving the camera to z = 5.

What Three.js is not

Three.js is a rendering library, not a game engine. It does not ship physics, a level editor, sound mixing or a ready-made character controller. You can add those with other libraries, and ecosystems such as react-three-fiber (see the later chapters on frameworks) build on top of it. This is a strength: you stay in control of the structure of your program.

Three.js also lives in the browser. It needs a WebGL-capable browser, which today means every mainstream desktop and mobile browser. A newer renderer built on WebGPU exists for the same scene API, but WebGL remains the default path and is what we use throughout this course.

Three.js releases often. Examples here pin version 0.170.0 in the import map so they keep working. When you upgrade a real project, read the migration notes, because small APIs are renamed between releases.

What you need to know first

You should be comfortable with basic JavaScript: variables, functions, arrow functions, objects and ES modules (see JavaScript modules). Classes help too, since Three.js is built from them (JavaScript classes). You do not need any math beyond the basics. We introduce vectors and rotations when they come up.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main reason to use Three.js instead of raw WebGL?

    Three.js still uses WebGL underneath. It hides shader compilation, buffer uploads and matrix math behind a friendly API.
  2. 2. Which two things does renderer.render() need?

    The scene says what exists, the camera says from where it is seen.
  3. 3. A Mesh is the combination of which two things?

    The geometry gives the shape, the material gives the surface look. You can reuse either one in other meshes.
  4. 4. How do you make an object appear to move?

    Animation is a loop: update, render, repeat, usually through requestAnimationFrame or renderer.setAnimationLoop.

Summary

  • Three.js is a JavaScript library that makes WebGL 3D graphics approachable.
  • A program needs a scene, a camera and a renderer; visible things are meshes (geometry + material).
  • renderer.render(scene, camera) draws one frame; a loop draws many.
  • MeshNormalMaterial needs no lights, which makes it ideal for quick tests.
  • Examples in this course pin a Three.js version through an import map.

Next: Setting Up a Three.js Project