Three.js Quick Start

A fast, practical way to start building with Three.js using the Codevre browser IDE. You’ll be coding online in a browser code editor with a clean file structure, OrbitControls, and a simple importmap (Codevre supports import maps smoothly). Great for creative coding, generative art coding, and quick prototypes in a three js browser editor.

Three.js 15 min Browser editor

What you’ll build

You’ll render a rotating cube with lights and OrbitControls. This is the “hello world” of Three.js and a great foundation for creative coding and generative art coding in a browser editor.

Project structure

The template is set up like a small, readable app. In the Codevre browser code editor, open:

  • /index.html — import map + loads /src/main.js
  • /src/main.js — scene wiring + render loop + resize handler
  • /src/scene.js — scene background color
  • /src/camera.js — camera position and perspective settings
  • /src/renderer.js — WebGLRenderer configuration
  • /src/cube.js — geometry + material
  • /src/lights.js — lighting setup

This template uses an importmap to pull ESM builds of Three.js. Codevre can handle import maps just fine—so this works smoothly in a browser IDE with no bundler.

Step 1 — Confirm the import map

In /index.html, the import map maps three and three/addons/. That means your browser IDE can resolve imports like OrbitControls without any extra setup.

<script type="importmap">
{
  "imports": {
    "three": "https://esm.sh/three@0.182.0",
    "three/examples/": "https://esm.sh/three@0.182.0/examples/",
    "three/addons/": "https://esm.sh/three@0.182.0/addons/"
  }
}
</script>

<script type="module" src="./src/main.js"></script>

Step 2 — Understand /src/main.js

main.js is the entry point. It creates a scene, camera, renderer, controls, adds a cube + lights, and starts the animation loop. This is the core structure you’ll reuse for most projects while coding online.

import { createScene } from './scene.js';
import { createCamera } from './camera.js';
import { createRenderer } from './renderer.js';
import { createCube } from './cube.js';
import { createLights } from './lights.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

const scene = createScene();
const camera = createCamera();
const renderer = createRenderer();

const controls = new OrbitControls(camera, renderer.domElement);
document.body.appendChild(renderer.domElement);

const cube = createCube();
scene.add(cube);

const { ambientLight, directionalLight } = createLights();
scene.add(ambientLight, directionalLight);

function animate() {
  requestAnimationFrame(animate);
  cube.rotation.x += 0.01;
  cube.rotation.y += 0.01;
  renderer.render(scene, camera);
}
animate();

window.addEventListener('resize', () => {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
});

Quick edits (make it yours)

Change the background

Open /src/scene.js and set a mood. Background choice makes a surprisingly big difference, especially for generative art coding.

import * as THREE from 'three';

export function createScene() {
  const scene = new THREE.Scene();
  scene.background = new THREE.Color('#0b1020');
  return scene;
}

Upgrade the cube material

In /src/cube.js, tweak material properties for a more “designed” look. Small adjustments to roughness and metalness can go a long way in a three js browser editor.

import * as THREE from 'three';

export function createCube() {
  const geometry = new THREE.BoxGeometry();
  const material = new THREE.MeshStandardMaterial({
    color: '#6d7bff',
    roughness: 0.35,
    metalness: 0.2
  });
  return new THREE.Mesh(geometry, material);
}

Make the motion more “generative”

Use time-based animation instead of constant increments. It’s an easy switch that makes motion feel more intentional and alive—perfect for creative coding.

import * as THREE from 'three';

const clock = new THREE.Clock();

function animate() {
  requestAnimationFrame(animate);

  const t = clock.getElapsedTime();
  cube.rotation.x = t * 0.6;
  cube.rotation.y = Math.sin(t) * 0.9;

  renderer.render(scene, camera);
}

When you want to expand beyond basics (controls, loaders, postprocessing), the Codevre browser IDE stays a solid workflow for coding online. Import maps help keep things clean, readable, and easy to remix.

Next steps

From here, try instancing, custom geometry, or shaders to push your generative art coding. This workflow stays fast in a browser editor when your files stay modular.

Three.js quick start Three.js tutorial three js browser editor browser IDE browser code editor coding online creative coding generative art coding WebGL import maps OrbitControls ESM

Ready to start creating?

Open the Three.js template in the Codevre browser IDE and start remixing.