W3Schools.com

HTML5 canvas clip Method

HTML5 track Tag Reference HTML5 canvas reference

Example

Write "Hello world", where only the parts inside the 200*150 pixels rectangle is visible:

Yor browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rect(10,15,200,75);
ctx.clip();
ctx.fillStyle="lightblue";
ctx.fillRect(0,0,300,150)
ctx.fillStyle="red";
ctx.font="30px Arial";
ctx.fillText("Hello world", 10,30);

Try it yourself »

Definition and Usage

The clip method creates an area in the canvas, described with the different path methods, and this area is the only visible area in the canvas.

JavaScript syntax: context.clip();


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The clip method is supported in all major browsers.



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