HTML canvas clip() Method

❮ HTML canvas Reference

Example

let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");

// Clip a rectangular area
ctx.rect(25, 25, 100, 100);
ctx.stroke();
ctx.clip();

// Draw red rectangle after clip()
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 150, 75);

Meaning

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


Standard Syntax

JavaScript syntax:

context.clip();



Browser Support




Status







❮ HTML canvas Reference