CanvasRenderingContext2D.currentTransform

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The CanvasRenderingContext2D.currentTransform property of the Canvas 2D API returns or sets a DOMMatrix (current specification) or SVGMatrix (old specification) object for the current transformation matrix.

Syntax

ctx.currentTransform [= value];
value
A DOMMatrix or SVGMatrix object to use as the current transformation matrix.

Examples

Using the currentTransform method

This is just a simple code snippet that uses the currentTransform property to set a transformation matrix.

HTML

<canvas id="canvas"></canvas>

JavaScript

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');

var matrix = ctx.currentTransform;
matrix.a = 1;
matrix.b = 1;
matrix.c = 0;
matrix.d = 1;
matrix.e = 0;
matrix.f = 0;
ctx.currentTransform = matrix;
ctx.fillRect(0, 0, 100, 100);

Edit the code below and see your changes update live in the canvas (make sure to use a browser that supports this feature — see the compatibility table):

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Experimental
Chrome Full support Yes
Disabled
Full support Yes
Disabled
Disabled This feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Full support YesFirefox No support No
Notes
No support No
Notes
Notes See bug 928150. Firefox also supports the experimental and prefixed properties mozCurrentTransform and mozCurrentTransformInverse which set or get the current (inverse) transformation matrix.
IE No support NoOpera No support NoSafari No support No
Notes
No support No
Notes
Notes See webkitbug(174278).
WebView Android No support NoChrome Android No support NoEdge Mobile Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
Returns a DOMMatrix
Experimental
Chrome No support No
Notes
No support No
Notes
Notes See https://crbug.com/637940.
Edge ? Firefox ? IE No support NoOpera No support NoSafari No support No
Notes
No support No
Notes
Notes See webkitbug(174278).
WebView Android No support No
Notes
No support No
Notes
Notes See https://crbug.com/637940.
Chrome Android No support No
Notes
No support No
Notes
Notes See https://crbug.com/637940.
Edge Mobile Full support YesFirefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also

Document Tags and Contributors

Last updated by: sideshowbarker,