Three.js is an open-source JavaScript library that draws interactive 3D scenes inside a web page by translating a high-level scene graph of objects, lights and cameras into low-level calls to WebGL or WebGPU. In real-time 3D, it is the most widely used way to put 3D graphics & animation into a browser without plugins, from product configurators and data visualizations to games and immersive marketing sites.
The library was started by the developer Ricardo Cabello in 2010 and is distributed under the permissive MIT license. It is not a game engine with an editor and physics built in. It is a rendering library: it handles meshes, materials, shaders, lighting and cameras, and leaves application logic, user interface and physics to the developer or to companion libraries.
How Three.js turns a scene into pixels
Every Three.js application is built from three core objects: a Scene, a Camera and a Renderer. The scene is a tree of objects with position, rotation and scale; the camera defines the viewpoint and projection; the renderer traverses the tree each frame and issues draw commands to the GPU.
Visible objects are usually a Mesh, which pairs a geometry (vertex positions, normals, UV coordinates stored in a BufferGeometry) with a material that decides how light affects the surface. During rendering, Three.js computes each object’s transformation matrix, performs frustum culling, sorts transparent objects, binds shaders and sends one draw call per mesh and material combination.
Animation happens in a render loop, typically driven by the browser’s requestAnimationFrame callback at the display refresh rate, often 60 frames per second. Code inside the loop updates object properties, advances animation mixers and then calls the renderer again.
Main building blocks of the library
Three.js exposes a layered set of classes that cover the whole rendering pipeline. The table summarizes the categories developers use in almost every project.
| Component | Examples | Role in the scene |
|---|---|---|
| Cameras | PerspectiveCamera, OrthographicCamera | Define viewpoint and projection |
| Geometries | BufferGeometry, BoxGeometry, SphereGeometry | Store vertices, normals and UVs |
| Materials | MeshStandardMaterial, MeshPhysicalMaterial, ShaderMaterial | Control shading and surface response |
| Lights | DirectionalLight, PointLight, SpotLight | Illuminate objects and cast shadows |
| Loaders | GLTFLoader, TextureLoader, DRACOLoader | Import models, textures and compressed meshes |
| Controls | OrbitControls, PointerLockControls | Map mouse and touch input to the camera |
| Post-processing | EffectComposer, bloom and ambient occlusion passes | Apply screen-space effects after rendering |
MeshStandardMaterial implements a physically based rendering model with metalness and roughness, which matches the material model of the glTF format. glTF 2.0 is the recommended exchange format, because models exported from Blender or other 3D software load with their materials, skeletons and animation clips largely intact.
Three.js compared with other web 3D options
Developers choosing a web 3D stack usually weigh Three.js against raw graphics APIs and fuller engines. The comparison shows where each option fits.
| Option | Level of abstraction | Strength | Trade-off |
|---|---|---|---|
| Three.js | Rendering library | Huge ecosystem, flexible, lightweight | No editor or physics built in |
| Babylon.js | Full engine | Editor tools, physics, strong typing | Larger bundle, more opinionated |
| Raw WebGL | Low-level API | Total control over the GPU | Verbose, slow to develop |
| Raw WebGPU | Low-level modern API | Compute shaders, lower overhead | Even more boilerplate code |
| React Three Fiber | Declarative wrapper | Three.js scenes as React components | Adds React dependency and abstraction |
In practice, Three.js is chosen when a team wants direct control with modest overhead and access to a very large body of examples. Babylon.js often wins for game-like projects that benefit from an integrated toolchain, while raw APIs are justified mainly for specialized rendering research or engines built from scratch.
Rendering backends and performance
Three.js historically rendered through WebGLRenderer, which uses WebGL 2 in current browsers. A newer WebGPURenderer targets the WebGPU API and falls back to WebGL when WebGPU is unavailable. Its node-based Three Shading Language (TSL) lets developers write shaders once in JavaScript and compile them for either backend.
Performance in the browser is limited mainly by draw calls, texture memory and shader cost, especially on mobile GPUs. The following decision table lists proven optimizations.
| Situation | Technique | Benefit |
|---|---|---|
| Thousands of identical objects | InstancedMesh | One draw call instead of thousands |
| Large downloadable models | Draco or Meshopt compression | Smaller files, faster loading |
| Heavy textures | KTX2 with Basis Universal | Compressed GPU textures, less memory |
| Static lighting | Baked lightmaps | Rich lighting without runtime cost |
| Distant detailed objects | Level of detail switching | Fewer vertices per frame |
Profiling should precede optimization. The renderer’s info object reports draw calls, triangles and loaded textures per frame, and browser developer tools reveal whether the bottleneck lies in JavaScript, the GPU or network loading.
Typical uses and common pitfalls
Three.js powers product configurators, architectural walkthroughs, scientific and geographic visualizations, browser games, WebXR experiences and award-oriented creative websites. Its small API surface makes it a common first step for web developers entering real-time rendering.
- Memory leaks: geometries, materials and textures must be disposed explicitly when removed, or GPU memory keeps growing.
- Wrong color management: textures need the correct color space, or scenes look washed out compared with the source 3D software.
- Too many unique materials: each material change can break batching and increase draw calls.
- Shadow map settings: oversized shadow maps cost memory, while undersized ones cause jagged edges and acne artifacts.
- Version drift: the library ships frequent numbered releases, and breaking changes between them require reading migration notes.
Because releases change APIs regularly, production teams usually pin an exact version and upgrade deliberately. Projects that rely on community examples should verify that each snippet matches the version in use.
A non-technical view
Three.js is a toolkit that lets a website show 3D objects you can turn and explore, right in an ordinary browser. Nobody needs to install an app or a plugin. The page simply loads the model and draws it.
Think of it as a stage crew for the graphics card. The developer describes the set, the lights and the camera. Three.js then handles the hard technical work of drawing it dozens of times every second.
A concrete example
An online furniture retailer wants shoppers to customize a sofa before buying. A small web team exports the sofa from Blender as a compressed glTF file of about 3 MB, loads it with GLTFLoader, and uses MeshPhysicalMaterial to show fabric and leather options with realistic sheen.
OrbitControls let customers rotate and zoom with a mouse or a finger. When a shopper picks a new fabric, the code swaps only the texture set instead of reloading the model. Baked ambient occlusion keeps lighting convincing on phones, and the configurator holds a stable 60 frames per second on mid-range devices. The result is a product page that works in any modern browser without a separate app.