CSS Reference ยท Filters, Masks and Shapes
The clip-path property
Reference for the CSS clip-path property: clip an element to a circle, ellipse, inset rectangle, polygon or path, with live examples and usage notes.
The clip-path property cuts an element to a shape. Anything outside the shape is not painted and does not receive pointer events. You can use basic shapes such as circle() and polygon(), a reference to an SVG <clipPath>, or a box keyword.
Clipping is hard-edged: a point is either inside or outside. For soft, semi-transparent edges use a mask instead.
.avatar { clip-path: circle(50%); }
Try it
Shapes with the same function and the same number of points can be animated, so the circle grows smoothly. Note that the hover target is only the visible part, because clipped areas do not receive pointer events.
Syntax
clip-path: none | <basic-shape> || <geometry-box> | url(#clip-id) /* <basic-shape>: inset() | circle() | ellipse() | polygon() | path() (and the newer rect(), xywh() and shape()) */ /* <geometry-box>: margin-box | border-box | padding-box | content-box | fill-box | stroke-box | view-box */
- Initial value:
none - Applies to: all elements; in SVG, all graphics and container elements
- Inherited: no
- Animatable: yes, between shapes of the same type (and same number of points for
polygon()) - Computed value:
none, a computed basic shape, plus the box if given, or the URL made absolute
Values
| Value | Description |
|---|---|
none |
No clipping. |
inset(top right bottom left round radius) |
A rectangle inset from the reference box; round adds corner radii. |
circle(radius at position) |
A circle. The radius can be a length, a percentage or closest-side / farthest-side. |
ellipse(rx ry at position) |
An ellipse with two radii. |
polygon(x y, x y, ...) |
Any straight-sided shape from a list of points; an optional first nonzero or evenodd sets the fill rule. |
path("M ...") |
A shape from SVG path syntax, in pixels. It does not scale with the element. |
url(#id) |
An SVG <clipPath> element, which can scale with the element via clipPathUnits="objectBoundingBox". |
<geometry-box> |
The box that percentages and the shape refer to. Default border-box. Alone, it clips to that box's edge. |
The shape functions are covered in circle() and basic shapes.
Usage notes
- Clipped parts are inert. They cannot be clicked, hovered or focused by pointer, but keyboard focus still works, so a clipped link remains reachable.
- Shadows and outlines are clipped too. A
box-shadoworoutlineoutside the shape disappears; applyfilter: drop-shadow()to a wrapper element to get a shadow that follows the shape. - Creates a stacking context when its value is not
none. - Percentages refer to the reference box, so
circle(50%)is relative to the box size (for circles, tosqrt(wยฒ + hยฒ) / sqrt(2), which makes50%of a square exactly fit). path()does not scale. For responsive shapes preferpolygon()with percentages, or an SVG<clipPath>withobjectBoundingBoxunits.- Accessibility. Clipping hides pixels only; the content stays in the accessibility tree. Do not use it to hide information visually if it must also be hidden from screen readers.
- Debugging. Temporarily set a bright background to see what the shape really covers.
Browser support
The basic shapes and url() references work in all current major browsers. Newer shape functions such as rect(), xywh() and shape() arrived later, so check a compatibility table before using them.
Related
maskโ soft-edged, image-based hidingshape-outsideโ wraps text around a shapefilterโ usedrop-shadow()for shadows on clipped shapescircle() and basic shapesโ the shape functions- Lesson: Clip Paths and Masks