On an <canvas>, every draw goes through a current transformation matrix. Helpers like translate, rotate, and scale change that matrix. transform(a, b, c, d, e, f) multiplies it by a custom matrix; setTransform(…) replaces it.
Use the matrix API for skew, one-shot resets, or combining effects. Prefer the named helpers when you only need move, turn, or zoom.
Baseline · Widely available.
transform and setTransform are stable Canvas 2D features across modern browsers since about July 2015.
Baseline · resetTransform() (Jan 2020+).
resetTransform() is widely available in modern browsers since about January 2020. Equivalent: setTransform(1, 0, 0, 1, 0, 0).
Multiplies, does not replace.
transform() stacks on the current matrix. Calling it twice compounds. Use setTransform / resetTransform / save+restore when you need a clean slate.
Syntax
Syntax
transform.js
// Multiply current matrix
ctx.transform(a, b, c, d, e, f);
// Replace matrix (identity → then apply)
ctx.setTransform(a, b, c, d, e, f);
// Back to identity
ctx.resetTransform();
// or: ctx.setTransform(1, 0, 0, 1, 0, 0);
Mapped point: (ax + cy + e, bx + dy + f). Identity is (1, 0, 0, 1, 0, 0).
resetTransform() returns to identity (fallback shown for older engines).
Green rect is axis-aligned again.
Also common: wrap temporary matrices in save()/restore().
Edge Cases & Pitfalls
Most matrix bugs are compounding transforms or confusing helpers with transform().
stack
transform compounds
Each transform() multiplies the current matrix. Unexpected skew or scale usually means a prior call was not reset.
order
Order matters
Translate then rotate ≠ rotate then translate. Plan the sequence, or use setTransform with a fully computed matrix.
helpers
Prefer helpers when possible
For everyday move/turn/zoom, translate/rotate/scale are clearer than raw a–f values.
leak
Isolate with save/restore
Temporary matrices should sit inside save()/restore() so later draws stay in identity (or the prior state).
Compatibility
Browser Support
transform and setTransform are part of Canvas 2D everywhere modern. resetTransform is widely available since about January 2020.
✓ Baseline · Widely available
transform / setTransform
Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the matrix APIs. Internet Explorer 9+ supports transform/setTransform; use setTransform(1,0,0,1,0,0) where resetTransform is missing.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet Explorer9+
transform/setTransform
transform()Widely supported
Bottom line: Safe for production matrix transforms. Prefer setTransform(1,0,0,1,0,0) as a reset fallback when needed.
Remember
Key Takeaways
Multiply:transform(a,b,c,d,e,f).
Replace:setTransform(…) or resetTransform().
Meaning: a/d scale, b/c skew, e/f translate.
Isolate:save() / restore().
One line: set or multiply the matrix → draw → reset or restore.
UA style
Default CSS Settings
Transforms are a Canvas API concern. The <canvas> element still uses typical user-agent CSS:
default.css
canvas {
display: inline;
}
CSS transform on the element scales the whole bitmap visually; it does not change the Canvas 2D matrix used by drawing calls.
Frequently Asked Questions
It multiplies the current transformation matrix by the matrix made from those six values. That can scale, skew, rotate, and translate in one step.
setTransform resets to the identity matrix first, then applies the given matrix. transform multiplies on top of whatever is already there.
a and d scale X/Y (when b and c are 0). b and c skew. e and f translate. A point (x, y) becomes (ax + cy + e, bx + dy + f).
For simple moves, turns, and zooms, the helpers are clearer. Use transform/setTransform for skew, custom matrices, or one-shot resets.
Call setTransform(1, 0, 0, 1, 0, 0), resetTransform(), or wrap changes in save()/restore().
Yes. Matrices multiply; translate-then-rotate is not the same as rotate-then-translate. Prefer save/restore around temporary matrices.