The <clipPath>
SVG element defines a clipping path. A clipping path is used/referenced using the clip-path
property.
The clipping path restricts the region to which paint can be applied. Conceptually, any parts of the drawing that lie outside of the region bounded by the currently active clipping path are not drawn.
<svg viewBox="0 0 100 100"> <clipPath id="myClip"> <!-- Everything outside the circle will be clipped and therefore invisible. --> <circle cx="40" cy="35" r="35" /> </clipPath> <!-- The original black heart for reference --> <path id="heart" d="M10,30 A20,20,0,0,1,50,30 A20,20,0,0,1,90,30 Q90,60,50,90 Q10,60,10,30 Z" /> <!-- Only the portion of the red heart inside the clip circle is visible. --> <use clip-path="url(#myClip)" xlink:href="#heart" fill="red" /> </svg>
/* With a touch of CSS for browsers who * * implemented the r Geometry Property. */ @keyframes openYourHeart {from {r: 0} to {r: 60px}} #myClip circle { animation: openYourHeart 15s infinite; }
A clipping path is conceptually equivalent to a custom viewport for the referencing element. Thus, it affects the rendering of an element, but not the element's inherent geometry. The bounding box of a clipped element (meaning, an element which references a <clipPath>
element via a clip-path
property, or a child of the referencing element) must remain the same as if it were not clipped.
By default, pointer-events
must not be dispatched on the clipped (non-visible) regions of a shape. For example, a circle with a radius of 10 which is clipped to a circle with a radius of 5 will not receive "click" events outside the smaller radius.
clipPathUnits
<clipPath>
element.userSpaceOnUse
|objectBoundingBox
; Default value: userSpaceOnUse
; Animatable: yes
id
class
, style
requiredExtensions
, systemLanguage
clip-path
, clip-rule
, color
, display
, fill
, fill-opacity
, fill-rule
, filter
, mask
, opacity
, shape-rendering
, stroke
, stroke-dasharray
, stroke-dashoffset
, stroke-linecap
, stroke-linejoin
, stroke-miterlimit
, stroke-opacity
, stroke-width
, transform
, vector-effect
, visibility
Categories | None |
---|---|
Permitted content | Any number of the following elements, in any order: Animation elements Descriptive elements Shape elements <text> , <use>
|
Specification | Status | Comment |
---|---|---|
CSS Masking Module Level 1 The definition of '<clipPath>' in that specification. | Candidate Recommendation | |
Scalable Vector Graphics (SVG) 1.1 (Second Edition) The definition of '<clipPath>' in that specification. | Recommendation | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 1 | Yes | 1.5 | 9 | 9 | 3 |
clipPathUnits |
Yes | Yes | Yes | 9 | Yes | 3 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 3 | Yes | Yes | 4 | Yes | 3 | ? |
clipPathUnits |
Yes | Yes | Yes | Yes | Yes | 3 | ? |
<mask>
clip-path
, pointer-events
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/clipPath