Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1047002 of <clipPath>

  • Revision slug: Web/SVG/Element/clipPath
  • Revision title: <clipPath>
  • Revision id: 1047002
  • Created:
  • Creator: Tigt
  • Is current revision? No
  • Comment Repaired viewBox attribute in code sample, removed useless code in same

Revision Content

{{SVGRefElem}}

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.

A clipping path is defined with a clipPath element. A clipping path is used/referenced using the {{SVGAttr("clip-path")}} property.

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 {{SVGAttr("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.

Usage context

{{svginfo}}

Example

<svg width="120" height="120"
     viewBox="0 0 120 120"
     xmlns="https://www.w3.org/2000/svg">

    <defs>
        <clipPath id="myClip">
            <circle cx="30" cy="30" r="20"/>
            <circle cx="70" cy="70" r="20"/>
        </clipPath>
    </defs>
    
    <rect x="10" y="10" width="100" height="100"
          clip-path="url(#myClip)"/>
    
</svg>

Live sample

{{EmbedLiveSample('Example','140','140')}}

Attributes

Global attributes

Specific attributes

  • {{SVGAttr("clipPathUnits")}}

DOM Interface

This element implements the SVGClipPathElement interface.

Specifications

Specification Status Comment
{{SpecName('SVG1.1', 'masking.html#EstablishingANewClippingPath', '<clipPath>')}} {{Spec2('SVG1.1')}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) IE Opera Safari
Basic support {{CompatChrome('1.0')}} {{CompatGeckoDesktop('1.8')}} {{CompatIE('9.0')}} {{CompatOpera('9.0')}} {{CompatSafari('3.0.4')}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatAndroid('3.0')}} {{CompatGeckoMobile('1.8')}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatSafari('3.0.4')}}

The chart is based on these sources.

  • {{SVGElement("mask")}}
  • {{SVGAttr("clip-path")}}

{{SVGRef}}

Revision Source

<p>{{SVGRefElem}}</p>

<p>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.</p>

<p>A clipping path is defined with a <code>clipPath</code> element. A clipping path is used/referenced using the {{SVGAttr("clip-path")}} property.</p>

<p>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 <code>clipPath</code> element via a {{SVGAttr("clip-path")}} property, or a child of the referencing element) must remain the same as if it were not clipped.</p>

<p>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.</p>

<h2 id="Usage_context">Usage context</h2>

<p>{{svginfo}}</p>

<h2 id="Example">Example</h2>

<pre class="brush: html">
&lt;svg width="120" height="120"
     viewBox="0 0 120 120"
     xmlns="https://www.w3.org/2000/svg"&gt;

    &lt;defs&gt;
        &lt;clipPath id="myClip"&gt;
            &lt;circle cx="30" cy="30" r="20"/&gt;
            &lt;circle cx="70" cy="70" r="20"/&gt;
        &lt;/clipPath&gt;
    &lt;/defs&gt;
    
    &lt;rect x="10" y="10" width="100" height="100"
          clip-path="url(#myClip)"/&gt;
    
&lt;/svg&gt;</pre>

<p><strong>Live sample</strong></p>

<p>{{EmbedLiveSample('Example','140','140')}}</p>

<h2 id="Attributes">Attributes</h2>

<h3 id="Global_attributes">Global attributes</h3>

<ul>
 <li><a href="/en-US/docs/Web/SVG/Attribute#ConditionalProccessing">Conditional processing attributes</a>&nbsp;»</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Core">Core attributes</a>&nbsp;»</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Presentation">Presentation attributes</a>&nbsp;»</li>
 <li>{{SVGAttr("class")}}</li>
 <li>{{SVGAttr("style")}}</li>
 <li>{{SVGAttr("externalResourcesRequired")}}</li>
 <li>{{SVGAttr("transform")}}</li>
</ul>

<h3 id="Specific_attributes">Specific attributes</h3>

<ul>
 <li>{{SVGAttr("clipPathUnits")}}</li>
</ul>

<h2 id="DOM_Interface">DOM&nbsp;Interface</h2>

<p>This element implements the <code><a href="/en-US/docs/Web/API/SVGClipPathElement">SVGClipPathElement</a></code> interface.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('SVG1.1', 'masking.html#EstablishingANewClippingPath', '&lt;clipPath&gt;')}}</td>
   <td>{{Spec2('SVG1.1')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>IE</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome('1.0')}}</td>
   <td>{{CompatGeckoDesktop('1.8')}}</td>
   <td>{{CompatIE('9.0')}}</td>
   <td>{{CompatOpera('9.0')}}</td>
   <td>{{CompatSafari('3.0.4')}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE&nbsp;Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatAndroid('3.0')}}</td>
   <td>{{CompatGeckoMobile('1.8')}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatSafari('3.0.4')}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>The chart is based on <a href="/en-US/docs/Web/SVG/Compatibility_sources">these sources</a>.</p>

<h2 id="Related">Related</h2>

<ul>
 <li>{{SVGElement("mask")}}</li>
 <li>{{SVGAttr("clip-path")}}</li>
</ul>

<p>{{SVGRef}}</p>
Revert to this revision