CSS clip-rule Property
The clip-rule property determines which regions of an SVG clipping path are considered inside the clipping area.
It uses one of two fill rules, nonzero or evenodd, to determine how overlapping paths, intersecting shapes, and enclosed regions affect clipping. This is particularly useful when a clipping path contains multiple subpaths or creates holes within a shape.
The property applies to SVG graphics elements within an SVG <clipPath> element. It does not directly control CSS basic shapes such as circle(), ellipse(), or inset().
clip-rule Syntax
The clip-rule property accepts two principal values: nonzero and evenodd.
selector {
clip-rule: nonzero;
}
General Syntax
selector {
clip-rule: nonzero | evenodd;
}
Nonzero Fill Rule
.svg-path {
clip-rule: nonzero;
}
Even-Odd Fill Rule
.svg-path {
clip-rule: evenodd;
}
SVG Presentation Attribute
The property can also be written as an SVG presentation attribute.
<path clip-rule="evenodd" d="..."></path>
When both CSS and the SVG presentation attribute specify a value, the CSS declaration takes precedence under normal cascade rules.
CSS-Wide Keywords
.svg-path {
clip-rule: inherit;
}
.svg-path {
clip-rule: initial;
}
.svg-path {
clip-rule: unset;
}
.svg-path {
clip-rule: revert;
}
.svg-path {
clip-rule: revert-layer;
}
Property Values
The two values differ in how they determine whether a point belongs to the clipping region.
| Value | Description |
|---|---|
nonzero |
Uses the nonzero winding rule to determine whether a point is inside the clipping path. This is the initial value. |
evenodd |
Counts path crossings and treats regions with an odd number of crossings as inside the clipping path. |
CSS-Wide Keywords
| Value | Description |
|---|---|
inherit |
Uses the computed value from the parent element. |
initial |
Resets the property to nonzero. |
unset |
Uses the inherited value because the property is inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | nonzero |
| Inherited | Yes |
| Applies to | SVG graphics elements |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
| Primary use | Determining the filled regions of SVG clipping paths |
Although clip-rule is an inherited SVG property, it only affects clipping when applied to the graphics elements that define an SVG clipping path.
How It Works
An SVG clipping path defines the region through which another element remains visible. The clip-rule property determines which parts of the clipping geometry count as inside that region.
Step 1: Define a Clipping Path
<svg width="200" height="200" viewBox="0 0 200 200">
<defs>
<clipPath id="example-clip">
<path d="M 20 20 H 180 V 180 H 20 Z"></path>
</clipPath>
</defs>
</svg>
Step 2: Set the Fill Rule
<clipPath id="example-clip">
<path clip-rule="evenodd" d="M 20 20 H 180 V 180 H 20 Z"></path>
</clipPath>
Step 3: Apply the Clipping Path
<rect x="0" y="0" width="200" height="200" fill="#1769aa" clip-path="url(#example-clip)"></rect>
Step 4: Determine the Visible Region
The browser evaluates the clipping path and paints the portions of the rectangle that fall inside its filled region.
Step 5: Understand Overlapping Subpaths
When the path contains multiple closed subpaths, nonzero and evenodd may produce different results. The difference is most noticeable when one shape is enclosed within another.
nonzero Fill Rule
The nonzero value uses the nonzero winding rule to determine whether a point belongs to the clipping region.
.svg-path {
clip-rule: nonzero;
}
How the Winding Rule Works
Imagine drawing a ray from a point to the outside of the shape. Each time the ray crosses a path segment, the winding count changes according to the direction of the crossing.
If the final winding count is not zero, the point is considered inside the clipping region.
Overlapping Shapes
When two enclosed subpaths follow the same winding direction, the overlapping interior generally remains filled.
Opposite Directions
When an inner subpath follows the opposite winding direction, it can cancel the outer path's winding count and create a hole.
SVG Example
<clipPath id="nonzero-clip">
<path clip-rule="nonzero" d="M 10 10 H 190 V 190 H 10 Z M 60 60 H 140 V 140 H 60 Z"></path>
</clipPath>
Both squares follow the same direction. Under the nonzero rule, the inner square remains part of the clipping region rather than becoming a hole.
Default Behavior
Because nonzero is the initial value, it applies when no other clipping rule is specified.
evenodd Fill Rule
The evenodd value determines whether a point is inside the clipping region by counting how many times a ray crosses the path.
.svg-path {
clip-rule: evenodd;
}
How the Even-Odd Rule Works
A point is considered inside the clipping region when the ray crosses the path an odd number of times.
A point is considered outside when the ray crosses the path an even number of times.
Creating Holes
The evenodd rule makes it straightforward to create a hole inside a larger shape without changing the direction of the inner path.
SVG Example
<clipPath id="evenodd-clip">
<path clip-rule="evenodd" d="M 10 10 H 190 V 190 H 10 Z M 60 60 H 140 V 140 H 60 Z"></path>
</clipPath>
The inner square creates a transparent opening in the clipping region because points inside it cross both the outer and inner boundaries.
Common Uses
The evenodd rule is useful for cutouts, hollow shapes, compound paths, and decorative graphics with transparent interior regions.
Path Direction and Winding
Path direction determines how the nonzero rule interprets overlapping and enclosed subpaths.
Same-Direction Subpaths
<path clip-rule="nonzero" d="M 10 10 H 190 V 190 H 10 Z M 60 60 H 140 V 140 H 60 Z"></path>
The outer and inner squares follow the same direction, so the inner region remains included under the nonzero rule.
Opposite-Direction Subpaths
<path clip-rule="nonzero" d="M 10 10 H 190 V 190 H 10 Z M 60 60 V 140 H 140 V 60 Z"></path>
The inner square follows the opposite direction, allowing its winding count to cancel the outer square and create a hole.
Direction with evenodd
<path clip-rule="evenodd" d="M 10 10 H 190 V 190 H 10 Z M 60 60 H 140 V 140 H 60 Z"></path>
Under evenodd, the inner square creates a hole regardless of its winding direction.
Choosing a Rule
Use nonzero when path direction is intentionally part of the design. Use evenodd when you want enclosed subpaths to create holes based on crossing counts.
Using clip-rule with SVG
The clip-rule property works with graphics elements inside SVG clipping paths.
Define a Compound Path
<svg width="200" height="200" viewBox="0 0 200 200">
<defs>
<clipPath id="compound-clip">
<path clip-rule="evenodd" d="M 10 10 H 190 V 190 H 10 Z M 60 60 H 140 V 140 H 60 Z"></path>
</clipPath>
</defs>
<rect width="200" height="200" fill="#1769aa" clip-path="url(#compound-clip)"></rect>
</svg>
Using CSS Instead of an Attribute
.compound-path {
clip-rule: evenodd;
}
<clipPath id="compound-clip">
<path class="compound-path" d="M 10 10 H 190 V 190 H 10 Z M 60 60 H 140 V 140 H 60 Z"></path>
</clipPath>
Referencing a Clipping Path from CSS
.clipped-element {
clip-path: url("#compound-clip");
}
The clip-rule declaration belongs on the SVG graphics element defining the clipping geometry, not on the HTML element being clipped.
Using an SVG Presentation Attribute
For small, self-contained SVG examples, the clip-rule attribute is often convenient. For reusable styling, a CSS class may be easier to maintain.
clip-rule vs. fill-rule
The clip-rule and fill-rule properties use the same two values, but they control different rendering operations.
| Feature | clip-rule | fill-rule |
|---|---|---|
| Purpose | Determines the inside region of clipping geometry | Determines the filled region of an SVG shape |
| Values | nonzero, evenodd |
nonzero, evenodd |
| Initial value | nonzero |
nonzero |
| Primary context | Graphics elements inside <clipPath> |
Filled SVG graphics |
Clipping Rule
.clip-shape {
clip-rule: evenodd;
}
Fill Rule
.filled-shape {
fill-rule: evenodd;
}
Important Difference
Setting fill-rule on a normal SVG shape affects how that shape is filled. Setting clip-rule on clipping geometry affects which parts of another element remain visible through the clipping path.
The two properties can be used independently on SVG graphics elements.
clip-rule vs. clip-path
The clip-path property defines the clipping region or references an SVG clipping path. The clip-rule property determines how the inside of certain SVG clipping shapes is calculated.
| Feature | clip-rule | clip-path |
|---|---|---|
| Purpose | Controls the fill rule for clipping geometry | Defines or references a clipping region |
| Values | nonzero, evenodd |
Basic shapes, geometry boxes, SVG references, and none |
| HTML elements | No direct clipping effect | Can clip HTML elements |
| SVG use | Determines which regions of clipping geometry are inside | Applies the clipping region to an element |
Define the Rule
.svg-clip-path {
clip-rule: evenodd;
}
Apply the Clipping Path
.clipped-element {
clip-path: url("#custom-clip");
}
The two properties work together when an SVG clipping path contains overlapping or enclosed subpaths.
CSS Basic Shapes
The clip-rule property does not directly change the fill rule of CSS basic shapes specified with clip-path.
Circle
.element {
clip-path: circle(45%);
}
Ellipse
.element {
clip-path: ellipse(45% 35%);
}
Inset
.element {
clip-path: inset(10px);
}
Polygon with an Explicit Fill Rule
.element {
clip-path: polygon(evenodd, 0 0, 100% 0, 100% 100%, 0 100%);
}
The polygon() function accepts an optional fill-rule argument directly. This is separate from the clip-rule property.
Default Polygon Rule
.element {
clip-path: polygon(nonzero, 0 0, 100% 0, 100% 100%, 0 100%);
}
When no fill rule is specified in polygon(), the default is nonzero.
For ordinary HTML clipping with CSS basic shapes, configure the fill rule through the shape function when that function supports it.
Practical Uses
The clip-rule property is most useful when SVG clipping paths contain compound shapes.
Create a Hollow Shape
.hollow-path {
clip-rule: evenodd;
}
An enclosed subpath can create a transparent opening within a larger clipping region.
Control Compound Paths
.compound-path {
clip-rule: nonzero;
}
The nonzero winding rule allows the direction of each subpath to influence the resulting clipping region.
SVG Cutout Effect
<clipPath id="cutout-clip">
<path clip-rule="evenodd" d="M 0 0 H 200 V 200 H 0 Z M 50 50 H 150 V 150 H 50 Z"></path>
</clipPath>
Reusable Clipping Geometry
.logo-cutout {
clip-path: url("#cutout-clip");
}
Decorative SVG Graphics
Compound clipping paths can be used to create borders, frames, cutouts, and other decorative vector effects.
Complex Vector Artwork
SVG artwork exported from vector design software may contain multiple subpaths. Understanding clip-rule helps explain why some enclosed regions appear filled while others become transparent.
clip-rule Example
The following example compares nonzero and evenodd using two nested squares drawn in the same direction.
With nonzero, the inner square remains part of the clipping region. With evenodd, the inner square becomes a transparent opening.
<div class="clip-rule-demo">
<div class="clip-rule-item">
<svg viewBox="0 0 200 200" role="img" aria-label="Solid blue square clipped using the nonzero rule">
<defs>
<clipPath id="clip-nonzero">
<path class="nonzero-path" d="M 10 10 H 190 V 190 H 10 Z M 60 60 H 140 V 140 H 60 Z"></path>
</clipPath>
</defs>
<rect width="200" height="200" fill="#1769aa" clip-path="url(#clip-nonzero)"></rect>
</svg>
<p>nonzero</p>
</div>
<div class="clip-rule-item">
<svg viewBox="0 0 200 200" role="img" aria-label="Blue square with a transparent center clipped using the evenodd rule">
<defs>
<clipPath id="clip-evenodd">
<path class="evenodd-path" d="M 10 10 H 190 V 190 H 10 Z M 60 60 H 140 V 140 H 60 Z"></path>
</clipPath>
</defs>
<rect width="200" height="200" fill="#1769aa" clip-path="url(#clip-evenodd)"></rect>
</svg>
<p>evenodd</p>
</div>
</div>
.clip-rule-demo {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 30px;
}
.clip-rule-demo .clip-rule-item {
width: 200px;
text-align: center;
}
.clip-rule-demo svg {
display: block;
width: 200px;
height: 200px;
background-color: #f0f0f0;
}
.clip-rule-demo .nonzero-path {
clip-rule: nonzero;
}
.clip-rule-demo .evenodd-path {
clip-rule: evenodd;
}
.clip-rule-demo p {
margin-top: 10px;
font-weight: bold;
}
nonzero
evenodd
The first example displays a solid blue square because both subpaths follow the same winding direction.
The second example displays a blue square with a transparent center because the evenodd rule excludes the region enclosed by both paths.
This demonstrates why clip-rule matters when SVG clipping paths contain nested or overlapping geometry.
Accessibility
The clip-rule property changes the visible clipping region but does not automatically change the accessibility semantics of an SVG graphic.
Provide Meaningful Labels
<svg role="img" aria-label="Decorative frame with a square opening" viewBox="0 0 200 200">
<!-- SVG clipping content -->
</svg>
Hide Decorative SVGs
<svg aria-hidden="true" focusable="false" viewBox="0 0 200 200">
<!-- Decorative SVG content -->
</svg>
Avoid Hiding Important Content
Do not rely on clipping alone to remove meaningful content from assistive technologies. Content hidden visually may still be represented in the accessibility tree.
Maintain Visual Contrast
When clipping creates thin borders or small decorative shapes, ensure the visible portions remain distinguishable against their backgrounds.
Use appropriate SVG semantics and accessible labels when the graphic conveys information.
Important Considerations
Keep the following points in mind when using clip-rule:
- Purpose: Determines which regions of SVG clipping geometry count as inside.
- Initial value:
nonzero. - Inheritance: The property is inherited.
- Values: Supports
nonzeroandevenodd. - SVG context: The property affects clipping geometry inside an SVG
<clipPath>element. - Path direction: The
nonzerorule uses winding direction to determine interior regions. - Crossing count: The
evenoddrule uses the number of path crossings. - Nested paths: Different rules may produce solid regions or transparent holes.
- Presentation attribute: SVG supports
clip-ruleas an attribute. - CSS cascade: CSS declarations override SVG presentation attributes when applicable.
- fill-rule: Controls normal SVG filling rather than clipping geometry.
- clip-path: Defines or references the clipping region.
- Basic shapes: CSS basic shapes do not directly use the
clip-ruleproperty. - Animation: Changes between
nonzeroandevenoddare discrete. - Accessibility: Clipping does not automatically remove content from the accessibility tree.
- Browser support: The property is supported by modern browsers for SVG clipping.
Use clip-rule when an SVG clipping path contains compound geometry and the default nonzero behavior does not produce the intended visible region.
Browser Support
The clip-rule property is supported in modern versions of Chrome, Edge, Firefox, and Safari for SVG clipping paths.
It is primarily an SVG-related property. Applying it to ordinary HTML elements does not directly create or modify a CSS clipping shape.
Supported SVG Usage
.svg-clip-shape {
clip-rule: evenodd;
}
SVG Presentation Attribute
<path clip-rule="evenodd" d="..."></path>
Compatibility Considerations
Browser support for SVG clipping paths is well established, but external SVG references and complex clipping combinations may require additional testing.
For current compatibility details, visit Can I Use? and search for clip-rule.
Specifications
The clip-rule property is defined in CSS Masking Module Level 1 and is associated with SVG clipping behavior.
These specifications describe the nonzero and even-odd rules used to determine the interior regions of SVG clipping geometry.
