{"id":189487,"date":"2014-12-02T09:59:57","date_gmt":"2014-12-02T16:59:57","guid":{"rendered":"http:\/\/css-tricks.com\/?p=189487"},"modified":"2016-11-06T14:07:27","modified_gmt":"2016-11-06T21:07:27","slug":"clipping-masking-css","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/clipping-masking-css\/","title":{"rendered":"Clipping and Masking in CSS"},"content":{"rendered":"

Both of these things are used to hide some parts of elements and show other parts. But there are, of course, differences between the two. Differences in what they can do, differences in syntaxes, different technologies involved, the new and the deprecated, and browser support differences. <\/p>\n

And sadly there is quite a bit of outdated information out there. Let’s see if we can sort it out.<\/p>\n

<\/p>\n

The difference between clipping and masking<\/h3>\n

Masks are images; Clips are paths. <\/p>\n

Imagine a square image that is a left-to-right, black-to-white gradient. That can be a mask. The element it is applied to will be transparent (see-through) where there is black in our gradient mask image, and opaque (normal) where there is white. So the final result will be an element that fades in from left to right.<\/p>\n

Clips are always vector paths. Outside the path is transparent, inside the path is opaque. <\/p>\n

I personally found this confusing, because often times you’ll run across a tutorial on masking that uses a masking image that a white vector-looking shape on black, so it is basically doing the same thing a clip. That’s fine, it just confuses things a bit.<\/p>\n

The Old\/Deprecated clip<\/code><\/h3>\n

The first presence of clipping in CSS (other than overflow: hidden;<\/code> trickery) was the clip<\/code> property. (MDN<\/a>).<\/p>\n

It was like this:<\/p>\n

.element {\r\n  clip: rect(10px, 20px, 30px, 40px);\r\n}<\/code><\/pre>\n

Those four values are in the same order as margin\/padding:<\/p>\n