jQuery plugin that makes easy to use clip-path on whatever tag under different browsers


This is a jQuery plugin that makes using clip-path property easy on whatever tag under different browsers.

Tested on Chrome and Firefox so far.

What it does?

Let's say that you want to achieve something like this:

So need to have a rectangle (e.g. 300x200) and you have to crop this image like with such coordinates: (0; 0), (145; 0), (150; 20), (155; 0), (300; 0), (300; 200), (0; 200), (0; 0)

In Webkit all you have to do is to write a css style: -webkit-clip-path: polygon(0 0, 145px 0, 150px 20px, 155px 0, 300px 0, 300px 200px, 0 200px, 0 0)

In Firefox and in W3C standard what you should do is: clip-path: url(#my-definition)

and somewhere in the file:

        <clippath id="my-definition">
            <polygon points="0 0, 145 0, 150 20, 155 0, 300 0, 300 200, 0 200, 0 0"></polygon>

clip-path-polygon does this job for you!

Install with or add it to your package.json:

$ npm install clip-path-polygon

Then require it:


and use:


Download clip-path-polygon.min.js (minified) or clip-path-polygon.js (dev) and add it to you HTML file:

<script src="clip-path-polygon.min.js"></script>

If you want to compile the whole package with unit tests, run: npm install

I use mocha, sinonjs and expect.js for testing.

Definition: clipPath(points [, options])

You cam call it on a jQuery element:


where points is an array of two-elements arrays: [[x0, y0], [x1, y1], [x2, y2]...] crops the element to this area defined by these points.

There are some options that you can use:

Option Default Description
isForWebkit *true* specifies if `-webkit-clip-path` property should be added to element
isForSvg *true* specifies if `-clip-path` property and `` element should be added
svgDefId *clipPathPolygonGenId* specifies *id* of SVG clippath definition
    <script src="jquery.min.js"></script> 
    <script src="clip-path-polygon.min.js"></script> 
      $(function() {
        var points = [[0, 0], [145, 0], [150, 20], [155, 0], [300, 0], [300, 200], [0, 200], [0, 0]];
    <div style="width: 300px; height: 200px">
      <div id="test" style="width: 100%; height: 100%; background-color: green"></div>

which gives you such an html code (remember that svg element has to have namespace!):

<div style="width: 300px; height: 200px">
  <div id="test" style="width: 100%; height: 100%; background-color: green;
    -webkit-clip-path: polygon(0 0, 145px 0, 150px 20px, 155px 0, 300px 0, 300px 200px, 0 200px, 0 0);
    clip-path: url(#clipPathPolygonGenId)"></div>
    <clippath id="clipPathPolygonGenId">
      <polygon points="0 0, 145 0, 150 20, 155 0, 300 0, 300 200, 0 200, 0 0"></polygon>