Canvas Transforms

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.
Learn translate → rotate around a pivot → scale → then the full matrix APIs.
Syntax
Translate to a pivot, rotate, then draw — wrap with save/restore:
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 topicUnderstand the current transform and the APIs that set or multiply it.
Common helpers
3 topicsEveryday moves you will use more often than raw matrix math.
Live Preview
Translate to the canvas center, then rotate and scale a card — the same order as the helper topics.
How to Learn Transforms
A practical order for this hub:
- Finish gradients and images from Color & Effects.
- Read
Transformso the matrix idea feels familiar. - Practice
translateto move the origin before you draw. - Add
rotateafter translate so shapes spin around a chosen pivot. - Try
scalefor zoom and mirrors (negative values flip). - Wrap local transforms in
save()/restore().
Frequently Asked Questions
Start with Canvas Transform
Open the matrix guide — setTransform, live preview, and examples.
8 people found this page helpful
