# JavaScript canvas libraries

JavaScript canvas libraries draw and update two-dimensional graphics in the browser through the HTML canvas element or SVG. Many of them keep each shape as an object that code can move, transform, or listen to for events. These libraries draw the diagrams, whiteboards, design editors, and games that run in web apps.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Rough.js](#roughjs) | 97.6M | 21.4K | Nov 2023 | MIT |
| [ZRender](#zrender) | 38.2M | 6.3K | May 2026 | BSD-3-Clause |
| [Konva](#konva) | 15.3M | 15.0K | Oct 2026 | MIT |
| [PixiJS](#pixijs) | 7.1M | 48.8K | Nov 2026 | MIT |
| [Fabric.js](#fabric-js) | 5.2M | 31.6K | May 2026 | MIT |
| [@antv/g](#antv-g) | 1.6M | 1.2K | Oct 2026 | MIT |
| [Paper.js](#paper-js) | 1.5M | 15.2K | Nov 2026 | MIT |
| [p5.js](#pfive) | 633.3K | 24.4K | Nov 2026 | LGPL-2.1 |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[Rough.js](#roughjs) has the most monthly downloads in this comparison, at 97.6M.

## Capabilities

| Library | SVG output | Canvas shape hit testing |
| --- | --- | --- |
| [Rough.js](#roughjs) | Yes | No |
| [ZRender](#zrender) | Yes | Yes |
| [Konva](#konva) | No | Yes |
| [PixiJS](#pixijs) | No | Yes |
| [Fabric.js](#fabric-js) | Yes | Yes |
| [@antv/g](#antv-g) | Via plugin | Yes |
| [Paper.js](#paper-js) | Yes | Yes |
| [p5.js](#pfive) | No | Undocumented |

## Libraries

### Rough.js

[GitHub](https://github.com/rough-stuff/rough) · [npm](https://www.npmjs.com/package/roughjs) · [Docs](https://roughjs.com)

Draws lines, curves, arcs, polygons, circles, and ellipses in a hand-drawn style on canvas or SVG.

- Downloads / mo: 97.6M
- Stars: 21.4K
- Last release: 4.6.6
- License: MIT
- Capabilities: [From the Rough.js docs](https://roughjs.com)

```sh
npm install roughjs
```

**excalidraw/excalidraw** (135.9K stars)

[excalidraw/excalidraw](https://github.com/excalidraw/excalidraw) 

```javascript
const generateArrowheadLinesToTip = (
  generator: RoughGenerator,
  arrowheadPoints: number[] | null,
  lineOptions: Options,
) => {
  if (arrowheadPoints === null) {
    return [];
  }

  const [x2, y2, x3, y3, x4, y4] = arrowheadPoints;

  return [
    generator.line(x3, y3, x2, y2, lineOptions),
    generator.line(x4, y4, x2, y2, lineOptions),
  ];
};
```

[packages/element/src/shape.ts](https://github.com/excalidraw/excalidraw/blob/d732d4f3d50e6ac092ec6e86a4e04a40546a9395/packages/element/src/shape.ts#L313-L328) · [More projects using Rough.js →](https://dashboard.exa.ai/playground/search?q=roughjs%20GitHub%20projects)

**Quickstart**

```javascript
import rough from 'roughjs';
const rc = rough.canvas(document.getElementById('canvas'));
rc.rectangle(10, 10, 100, 80);

```

From [Rough.js wiki](https://github.com/pshihn/rough/wiki)

### ZRender

[GitHub](https://github.com/ecomfe/zrender) · [npm](https://www.npmjs.com/package/zrender) · [Docs](https://github.com/ecomfe/zrender#readme)

Draws the two-dimensional graphics underneath Apache ECharts.

- Downloads / mo: 38.2M
- Stars: 6.3K
- Last release: 6.1.0
- License: BSD-3-Clause
- Capabilities: [From the ZRender docs](https://github.com/ecomfe/zrender#readme)

```sh
npm install zrender
```

**apache/echarts** (67.8K stars)

[apache/echarts](https://github.com/apache/echarts) 

```javascript
export function makePath(
    pathData: string,
    opts: SVGPathOption,
    rect: ZRRectLike,
    layout?: 'center' | 'cover'
): SVGPath {
    const path = pathTool.createFromString(pathData, opts);
    if (rect) {
        if (layout === 'center') {
            rect = centerGraphic(rect, path.getBoundingRect());
        }
        resizePath(path, rect);
    }
    return path;
}
```

[src/util/graphic.ts](https://github.com/apache/echarts/blob/34f4d927eafe251f26f63afd3aeefa30f2feba30/src/util/graphic.ts#L184-L198) · [More projects using ZRender →](https://dashboard.exa.ai/playground/search?q=zrender%20GitHub%20projects)

**Quickstart**

```javascript
import * as zrender from 'zrender';
const zr = zrender.init(document.getElementById('main'));
zr.add(new zrender.Circle({ shape: { cx: 80, cy: 80, r: 40 }, style: { fill: 'red' } }));

```

From [api.html](https://ecomfe.github.io/zrender-doc/public/api.html)

### Konva

[GitHub](https://github.com/konvajs/konva) · [npm](https://www.npmjs.com/package/konva) · [Docs](https://konvajs.org/)

Provides a canvas scene graph with shape events, dragging, transforms, animation, and image export.

- Downloads / mo: 15.3M
- Stars: 15.0K
- Last release: 10.9.1
- License: MIT
- Capabilities: [From the Konva docs](https://konvajs.org/)

**Strengths**

- **Gives each shape interaction events.** Handle dragging, transforms, and animation on individual scene nodes.
- **Restores serialized node trees.** Create a stage from JSON and reconnect application behavior afterward.

**Watch out for**

- **Text input needs DOM elements.** Overlay a native text input or textarea for editing.
- **JSON omits images and handlers.** Restore image assets and event listeners after loading a saved stage.

```sh
npm install konva
```

**konvajs/react-konva** (6.4K stars)

[konvajs/react-konva](https://github.com/konvajs/react-konva) 

```javascript
export function applyNodeProps(instance, props, oldProps = EMPTY_PROPS) {
  // don't use zIndex in react-konva
  if (!zIndexWarningShowed && 'zIndex' in props) {
    console.warn(Z_INDEX_WARNING);
    zIndexWarningShowed = true;
  }

  // check correct draggable usage
  if (!dragWarningShowed && props.draggable) {
    var hasPosition = props.x !== undefined || props.y !== undefined;
    var hasEvents = props.onDragEnd || props.onDragMove;
    if (hasPosition && !hasEvents) {
      console.warn(DRAGGABLE_WARNING);
      dragWarningShowed = true;
    }
  }

  var updatedProps = {};
  var hasUpdates = false;

  // check old props
  // we need to unset properties that are not in new props
  // and remove all events
  for (var key in oldProps) {
    if (propsToSkip[key]) {
      continue;
    }
    var isEvent = key.slice(0, 2) === 'on';
    var propChanged = oldProps[key] !== props[key];

    // if that is a changed event, we need to remove it
    if (isEvent && propChanged) {
      var eventName = key.substr(2).toLowerCase();
      if (eventName.substr(0, 7) === 'content') {
        eventName =
          'content' +
          eventName.substr(7, 1).toUpperCase() +
          eventName.substr(8);
      }
      // Remove by namespace because react-konva binds at most one listener
      // for each event in that namespace.
      instance.off(eventName + EVENTS_NAMESPACE);
    }
    var toRemove = !props.hasOwnProperty(key);
    if (!isEvent && toRemove) {
      updatedProps[key] = undefined;
      hasUpdates = true;
    }
  }

  var strictUpdate = useStrictMode || props._useStrictMode;
  const newEvents = {};

  for (var key in props) {
    if (propsToSkip[key]) {
      continue;
    }
    var isEvent = key.slice(0, 2) === 'on';
    var toAdd = oldProps[key] !== props[key];
    if (isEvent && toAdd) {
      var eventName = key.substr(2).toLowerCase();
      if (eventName.substr(0, 7) === 'content') {
        eventName =
          'content' +
          eventName.substr(7, 1).toUpperCase() +
          eventName.substr(8);
      }
      // check that event is not undefined
      if (props[key]) {
        newEvents[eventName] = props[key];
      }
    }
    if (
      !isEvent &&
      (props[key] !== oldProps[key] ||
        (strictUpdate && props[key] !== instance.getAttr(key)))
    ) {
      hasUpdates = true;
      updatedProps[key] = props[key];
    }
  }

  if (hasUpdates) {
    instance.setAttrs(updatedProps);
    updatePicture(instance);
  }

  // subscribe to events AFTER we set attrs
  // we need it to fix https://github.com/konvajs/react-konva/issues/471
  // settings attrs may add events. Like "draggable: true" will add "mousedown" listener
  for (var eventName in newEvents) {
    // first clear any existing listeners, it is required for strict mode
    instance.off(eventName + EVENTS_NAMESPACE);
    // then attach new one
    instance.on(eventName + EVENTS_NAMESPACE, newEvents[eventName]);
  }
}
```

[src/makeUpdates.ts](https://github.com/konvajs/react-konva/blob/be9feb46cacfdff6c4c3bb0277b222448c7c94f7/src/makeUpdates.ts#L38-L134) · [More projects using Konva →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20projects%20using%20konva%20for%20editor%20JSON%20restoration%2C%20canvas%20node%20reconciliation%2C%20Bezier%20geometry%20and%20zoomed%20viewport%20coordinate%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import Konva from 'konva';
const stage = new Konva.Stage({ container: 'container', width: 300, height: 200 });
const layer = new Konva.Layer();
layer.add(new Konva.Circle({ x: 80, y: 80, radius: 40, fill: 'red' }));
stage.add(layer);

```

From [README.md](https://konvajs.org/docs/overview.html)

### PixiJS

[GitHub](https://github.com/pixijs/pixijs) · [npm](https://www.npmjs.com/package/pixi.js) · [Docs](http://pixijs.com/)

Builds rendered scenes from sprites, graphics, text, and assets, with SVG texture or geometry loading.

- Downloads / mo: 7.1M
- Stars: 48.8K
- Last release: 8.23.0
- License: MIT
- Capabilities: [From the PixiJS docs](http://pixijs.com/)

**Strengths**

- **Loads SVG textures or geometry.** Choose sprite textures or editable Graphics geometry for SVG artwork.
- **Exports rendered content as PNG.** Download a scene or object as a PNG image.

**Watch out for**

- **Changing text rebuilds its texture.** Use BitmapText for text that changes every frame.
- **SVG textures lose vector scalability.** Use Graphics geometry when SVG artwork must scale cleanly.

```sh
npm install pixi.js
```

**pixijs-userland/pixi-viewport** (1.2K stars)

[pixijs-userland/pixi-viewport](https://github.com/pixijs-userland/pixi-viewport) 

```javascript
public toWorld<P extends PointData = Point>(x: number | PointData, y?: number): P
    {
        if (arguments.length === 2)
        {
            return this.toLocal<P>(new Point(x as number, y));
        }

        return this.toLocal<P>(x as PointData);
    }
```

[src/Viewport.ts](https://github.com/pixijs-userland/pixi-viewport/blob/e6423e72f1055f5446f015fa0eed3dc29c8a7f13/src/Viewport.ts#L412-L420) · [More projects using PixiJS →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20projects%20using%20pixi.js%20for%20editor%20JSON%20restoration%2C%20canvas%20node%20reconciliation%2C%20Bezier%20geometry%20and%20zoomed%20viewport%20coordinate%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import { Application, Graphics } from 'pixi.js';
const app = new Application();
await app.init({ width: 300, height: 200 });
document.body.appendChild(app.canvas);
app.stage.addChild(new Graphics().rect(20, 20, 100, 80).fill('red'));

```

From [README.md](https://pixijs.download/v8.23.0/docs/app.Application.html)

### Fabric.js

[GitHub](https://github.com/fabricjs/fabric.js) · [npm](https://www.npmjs.com/package/fabric) · [Docs](http://fabricjs.com/)

Adds interactive objects, transform controls, editable text, and scene serialization to a canvas.

- Downloads / mo: 5.2M
- Stars: 31.6K
- Last release: 7.4.0
- License: MIT
- Capabilities: [From the Fabric.js docs](http://fabricjs.com/)

**Strengths**

- **Provides ready-made object controls.** Move, scale, rotate, skew, and group objects with built-in interactions.
- **Edits text directly on canvas.** IText enters an editing state for interactive text input.

**Watch out for**

- **Custom fields need export registration.** Register application-specific properties before including them in serialized objects.

```sh
npm install fabric
```

**xRyul/obsidian-image-converter** (842 stars)

[xRyul/obsidian-image-converter](https://github.com/xRyul/obsidian-image-converter) 

```javascript
private clearAll() {
		if (!this.canvas) return;
	
		const message = 'Are you sure you want to clear all annotations?';
		const confirmText = 'Clear';
	
		new ConfirmDialog(this.app, 'Clear Annotations', message, confirmText, () => {
			const objects = this.canvas.getObjects();
			// Remove all objects except the background image (first object)
			objects.slice(1).forEach(obj => this.canvas.remove(obj));
			this.canvas.requestRenderAll();
			this.saveState(); // IMPORTANT: Save the cleared state
		}).open();
	}

```

[src/ImageAnnotation.ts](https://github.com/xRyul/obsidian-image-converter/blob/e383c4dd4d1ea9852a14d75afad8f495f83d1298/src/ImageAnnotation.ts#L2598-L2611) · [More projects using Fabric.js →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20projects%20using%20fabric%20for%20editor%20JSON%20restoration%2C%20canvas%20node%20reconciliation%2C%20Bezier%20geometry%20and%20zoomed%20viewport%20coordinate%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import { Canvas, Rect } from 'fabric';
const canvas = new Canvas('canvas', { width: 300, height: 200 });
canvas.add(new Rect({ left: 20, top: 20, width: 100, height: 80, fill: 'red' }));

```

From [README.md](https://fabricjs.com/api/classes/canvas/)

### @antv/g

[GitHub](https://github.com/antvis/G) · [npm](https://www.npmjs.com/package/@antv/g) · [Docs](https://github.com/antvis/g#readme)

Renders graphics through DOM-compatible element and event APIs.

- Downloads / mo: 1.6M
- Stars: 1.2K
- Last release: 6.3.3
- License: MIT
- Capabilities: [From the @antv/g docs](https://github.com/antvis/g#readme)

```sh
npm install @antv/g @antv/g-canvas
```

**antvis/G6** (12.4K stars)

[antvis/G6](https://github.com/antvis/G6) 

```javascript
protected onPointerDown(event: IPointerEvent) {
    if (!this.validate(event) || !this.isKeydown() || this.startPoint) return;
    const { canvas, graph } = this.context;
    const style = { ...this.options.style };

    // 根据缩放比例调整 lineWidth
    // Adjust lineWidth according to the zoom ratio
    if (this.options.style.lineWidth) {
      style.lineWidth = +this.options.style.lineWidth / graph.getZoom();
    }

    this.rectShape = new Rect({ id: 'g6-brush-select', style });
    canvas.appendChild(this.rectShape);

    this.startPoint = [event.canvas.x, event.canvas.y];
  }
```

[packages/g6/src/behaviors/brush-select.ts](https://github.com/antvis/G6/blob/e64ab9af480b6f3a0a40db1c62a924d340c06ee1/packages/g6/src/behaviors/brush-select.ts#L144-L159) · [More projects using @antv/g →](https://dashboard.exa.ai/playground/search?q=%40antv/g%20GitHub%20projects)

**Quickstart**

```javascript
import { Canvas, Circle } from '@antv/g';
import { Renderer } from '@antv/g-canvas';
const canvas = new Canvas({ container: 'container', width: 300, height: 200, renderer: new Renderer() });
await canvas.ready;
canvas.appendChild(new Circle({ style: { cx: 80, cy: 80, r: 40, fill: 'red' } }));

```

From [getting-started](https://g.antv.antgroup.com/en/guide/getting-started)

### Paper.js

[GitHub](https://github.com/paperjs/paper.js) · [npm](https://www.npmjs.com/package/paper) · [Docs](http://paperjs.org)

Provides a vector scene graph with paths, point geometry, SVG import, and project serialization.

- Downloads / mo: 1.5M
- Stars: 15.2K
- Last release: 0.17.0
- License: MIT
- Capabilities: [From the Paper.js docs](http://paperjs.org)

**Strengths**

- **Imports SVG as editable items.** Convert external SVG artwork into Paper.js project items.
- **Serializes complete vector projects.** Restore saved JSON data into a project.

**Watch out for**

- **Node rendering needs extra packages.** Use paper-jsdom-canvas for server-side canvas rendering.

```sh
npm install paper
```

**glenzli/paperjs-offset** (122 stars)

[glenzli/paperjs-offset](https://github.com/glenzli/paperjs-offset) 

```javascript
function offsetSegment(segment: paper.Segment, curve: paper.Curve, handleNormal: paper.Point, offset: number) {
  const isFirst = segment.curve === curve;
  // get offset vector
  const offsetVector = (curve.getNormalAtTime(isFirst ? 0 : 1)).multiply(offset);
  // get offset point
  const point = segment.point.add(offsetVector);
  const newSegment = new paper.Segment(point);
  // handleOut for start segment & handleIn for terminal segment
  const handle = (isFirst ? 'handleOut' : 'handleIn') as HandleType;
  newSegment[handle] = segment[handle]!.add(handleNormal.subtract(offsetVector).divide(2));
  return newSegment;
}
```

[src/offset_core.ts](https://github.com/glenzli/paperjs-offset/blob/f3ed87fc640bc101f9d9454e1748a3e3c15b335e/src/offset_core.ts#L85-L96) · [More projects using Paper.js →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20projects%20using%20paper%20for%20editor%20JSON%20restoration%2C%20canvas%20node%20reconciliation%2C%20Bezier%20geometry%20and%20zoomed%20viewport%20coordinate%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import paper from 'paper';
paper.setup(document.getElementById('canvas'));
new paper.Path.Circle({ center: [80, 80], radius: 40, fillColor: 'red' });

```

From [README.md](https://paperjs.org/tutorials/getting-started/using-javascript-directly/)

### p5.js

[GitHub](https://github.com/processing/p5.js) · [npm](https://www.npmjs.com/package/p5) · [Docs](https://p5js.org)

Draws shapes, text, and color on a canvas in a sketch that responds to the mouse.

- Downloads / mo: 633.3K
- Stars: 24.4K
- Last release: 2.4.0
- License: LGPL-2.1
- Capabilities: [From the p5.js docs](https://p5js.org)

```sh
npm install p5
```

**CodingTrain/Coding-Challenges** (191 stars)

[CodingTrain/Coding-Challenges](https://github.com/CodingTrain/Coding-Challenges) 

```javascript
function draw() {
  background(0);

  if (i < values.length) {
    for (let j = 0; j < values.length - i - 1; j++) {
      let a = values[j];
      let b = values[j + 1];
      if (a > b) {
        swap(values, j, j + 1);
      }
    }
  } else {
    console.log('finished');
    noLoop();
  }
  i++;

  for (let i = 0; i < values.length; i++) {
    stroke(255);
    line(i, height, i, height - values[i]);
  }
}
```

[114_BubbleSortViz/P5/sketch.js](https://github.com/CodingTrain/Coding-Challenges/blob/576bc7c1b60e2fadf4a18e81b06e359cda57751a/114_BubbleSortViz/P5/sketch.js) · [More projects using p5.js →](https://dashboard.exa.ai/playground/search?q=p5%20GitHub%20projects)

**Quickstart**

```javascript
function setup() {
  createCanvas(400, 400);
}
function draw() {
  background(220);
}

```

From [get-started](https://p5js.org/tutorials/get-started/)

## FAQ

### Which JavaScript canvas library should I use?

[Konva](#konva) and [Fabric.js](#fabric-js) keep each shape as an object with its own events and transforms, the model behind editors and whiteboards. [PixiJS](#pixijs) renders sprite and graphics scenes, and [Paper.js](#paper-js) works with editable vector paths.

### What is Rough.js?

[Rough.js](#roughjs) draws lines, curves, arcs, polygons, circles, and ellipses in a hand-drawn, sketchy style on canvas or SVG. It has the most monthly downloads of these libraries, at 97.6M.

### Konva vs Fabric: which should I use?

Fabric.js ships built-in controls to move, scale, rotate, and skew objects, and its IText edits text directly on the canvas. Konva gives each shape its own events and drag behavior, and text editing goes through a DOM input.

### Can users edit Konva text directly inside the canvas?

Konva does not support direct Konva.Text editing and recommends native DOM inputs. Fabric IText has a native editing state.

### Does saving Konva JSON preserve images and event handlers?

Images and event handlers must be manually restored after loading.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript canvas libraries Fabric.js Konva Paper.js PixiJS code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
