Clipping and Masking
suggest changeClipping and masking both limit what is painted, but they use different models:
clip-pathdefines a hard boundary. Pixels are either inside or outside the clip.mask-imageuses alpha or luminance values, allowing partial transparency and soft edges.
Clipping
.avatar {
clip-path: circle(50%);
}
.badge {
clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
Basic shape functions include inset(), circle(), ellipse(), and polygon(). A url() can reference an SVG clip path.
Masking
.faded-image {
mask-image: linear-gradient(to bottom, black 70%, transparent);
mask-repeat: no-repeat;
mask-size: cover;
}
Mask layers use properties analogous to backgrounds, including mask-position, mask-size, mask-repeat, mask-origin, and mask-clip.
Modern browsers implement the standard unprefixed clipping and masking properties for common cases. If a complex mask is decorative, provide a readable unclipped baseline and test the exact mask mode, image source, and compositing behavior required by the project.
Clipping does not change layout geometry or the element's accessibility tree. Do not clip away focusable controls or essential content.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents