W3Schools.com

HTML5 canvas scale Method

HTML5 track Tag Reference HTML5 canvas reference

Example

Draw a small rectangle, scale five times, and draw the same rectangle again:

Yor browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.strokeRect(5,5,25,15);
ctx.scale(5,5);
ctx.strokeRect(5,5,25,15);

Try it yourself »

Definition and Usage

The scale method scales the drawings, bigger or smaller.

You can scale the width or the height or both, by using the two parameters

If you scale both width and height two times (2,2) all drawings, from now on, will be twice as wide and twice as high as you specify

Also, the positioning will be scaled. If you scale (2,2), drawings will be positioned twice as far from the left, and top, of the canvas.

JavaScript syntax: context.scale(x,y);


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The scale method is supported in all major browsers.


Parameter Values

Parameter Values Description Play it
x width The scaling of the the width. 1= no scaling, 0.5= half the size,2= twice the size etc. Play it »
y height The scaling of the the height. 1= no scaling, 0.5= half the size,2= twice the size etc. 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
XML Editor - Free Trial!
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