W3Schools.com

HTML5 canvas rotate Method

HTML5 track Tag Reference HTML5 canvas reference

Example

Rotate a rectangle 20 degrees:

Yor browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rotate(20*Math.PI/180);
ctx.fillRect(50,50,100,50);

Try it yourself »

Definition and Usage

The rotate method rotates the canvas.

The rotation is done in an angle from the canvas' position 0,0:

The rotate method takes one parameter, radians.

The parameter decides the degree of the rotation by using radians.

To calculate from degrees to radians, use this formula: degrees*PI/180

20 degrees: 20*PI/180=0.35

The rotation will only affect drawings made AFTER the rotation is done.

JavaScript syntax: context.rotate(angle);


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The rotate method is supported in all major browsers.


Parameter Values

Parameter Values Description Play it
angle angle Rotates the canvas to the given angle Play it »

HTML5 track Tag Reference HTML5 canvas reference


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE