Tutorials References Exercises Menu
Paid Courses

HTML canvas clip() Method

❮ HTML Canvas Reference


Clip of a rectangular region of 200*120 pixels from the canvas. Then, draw a red rectangle. Only the part of the red rectangle that is inside the clipped area is visible:



var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
// Clip a rectangular area
ctx.rect(50, 20, 200, 120);
// Draw red rectangle after clip()
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 150, 100);
Try it Yourself »

Browser Support

The numbers in the table specify the first browser version that fully supports the method.

clip() Yes 9.0 Yes Yes Yes

Definition and Usage

The clip() method clips a region of any shape and size from the original canvas.

Tip: Once a region is clipped, all future drawing will be limited to the clipped region (no access to other regions on the canvas). You can however save the current canvas region using the save() method before using the clip() method, and restore it (with the restore() method) any time in the future.

JavaScript syntax: context.clip();

❮ HTML Canvas Reference