JavaScript library for vector shapes and animation with the same API on SVG, Canvas 2D, and WebGL. Includes scenegraph, SVG import, and bitmap support.
Overview
Two.js is a two-dimensional drawing API for modern web browsers. The same code can render through SVG, Canvas 2D, or WebGL because the library is renderer agnostic, which helps projects switch or compare backends without rewriting scene code.
It uses a scenegraph: paths and groups are stored objects that accept transforms such as rotation, position, and scale after creation. Groups propagate styling to child shapes. A built-in animation loop can run automatically or bind to external update events.
An SVG interpreter allows shapes authored in tools like Adobe Illustrator to enter a Two.js scene. Bitmap workflows cover single images, sprite sheets, and image sequences. It targets flat motion graphics and concise shape animation APIs.
You add the library via a script tag or npm install. ES6 imports are supported for bundlers such as webpack and Vite. Headless server rendering is possible with Node Canvas on the server side. Documentation and examples cover React, Angular, and standalone HTML pages.
Key features
- SVG, Canvas, and WebGL renderers
- Scenegraph paths and groups
- Built-in animation loop
- SVG interpreter for imports
- Bitmap and sprite sheet loading
- npm package and ES modules
- Headless Node Canvas option
- Shape transform and styling
Use cases
- 2D web animations
- Interactive vector graphics
- Illustrator SVG in the browser
- React or Angular canvases
- Server-side frame rendering