Canvas Transforms

Beginner
7 min read
Updated: Nov 2026
4 topic guides
Transforms hub

Definition

Transforms change how later drawing commands map onto the canvas: move the origin with translate, turn with rotate, resize with scale, or set the full matrix with transform / setTransform.

After fills from Color & Effects, open Transform for the matrix model, then Translate, Rotate, and Scale.

Beginner path.

Learn translate → rotate around a pivot → scale → then the full matrix APIs.

Syntax

Translate to a pivot, rotate, then draw — wrap with save/restore:

JavaScript
const canvas = document.getElementById("demo");
const ctx = canvas.getContext("2d");

ctx.save();
ctx.translate(200, 110);          // move origin to center
ctx.rotate((30 * Math.PI) / 180); // 30 degrees
ctx.scale(1.2, 1.2);              // slightly larger
ctx.fillStyle = "#2563eb";
ctx.fillRect(-40, -25, 80, 50);   // drawn relative to new origin
ctx.restore();

Topics

Guides in the Transforms section (4 tutorials).

Matrix basics

1 topic

Understand the current transform and the APIs that set or multiply it.

TopicDescriptionTutorial
Transformtransform, setTransform, resetTransform, and the matrix model.Open

Common helpers

3 topics

Everyday moves you will use more often than raw matrix math.

TopicDescriptionTutorial
TranslateMove the origin with translate(x, y).Open
RotateTurn later draws with rotate(angle in radians).Open
ScaleGrow, shrink, or flip with scale(x, y).Open

Live Preview

Translate to the canvas center, then rotate and scale a card — the same order as the helper topics.

30
1.20

Crosshair marks the translated origin; the blue card is drawn relative to it.

Canvas

rotate="30" scale="1.20"

How to Learn Transforms

A practical order for this hub:

  1. Finish gradients and images from Color & Effects.
  2. Read Transform so the matrix idea feels familiar.
  3. Practice translate to move the origin before you draw.
  4. Add rotate after translate so shapes spin around a chosen pivot.
  5. Try scale for zoom and mirrors (negative values flip).
  6. Wrap local transforms in save() / restore().

Frequently Asked Questions

Changing the current transformation matrix so later draws move (translate), turn (rotate), or resize (scale). The Transform topic also covers the full matrix helpers.
No. They change how future drawing commands map onto the bitmap. Pixels already painted stay where they are until you clear or overwrite them.
rotate() turns around the origin (0,0) by default. translate() to the pivot you want first, then rotate, so shapes spin around their center instead of the canvas corner.
Prefer save() before changing the matrix and restore() after. You can also call setTransform(1, 0, 0, 1, 0, 0) to reset to identity, or invert what you applied carefully.
transform() multiplies the current matrix by another. setTransform() replaces the current matrix. Both are covered on the Transform topic page.
This page is the index for the Transforms sidebar section. Each topic page (Transform, Translate, Rotate, Scale) has full syntax, live demos, examples, and FAQs.

Start with Canvas Transform

Open the matrix guide — setTransform, live preview, and examples.

Canvas Transform →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful