files/en-us/web/css/reference/properties/fill-rule/index.md
The fill-rule CSS property defines the rule used to determine which parts of the SVG shape's canvas are included inside a shape to be filled. If present, it overrides the element's {{SVGAttr("fill-rule")}} attribute.
The fill-rule clarifies which areas of a shape should be considered "inside" the shape. It provides two values you can set to tell the browser how the inside of a shape should be determined. For shapes that don't have intersecting paths, like a circle, the bounds of what is inside a shape to be filled are intuitively clear. With complex shapes that include intersecting paths (such as a Venn diagram) or paths enclosing other paths (such as a donut), the interpretation of which sections of the shape are "inside" the shape and should be filled by the {{cssxref("fill")}} property, may not be obvious.
[!NOTE] The
fill-ruleproperty only applies to {{SVGElement("path")}}, {{SVGElement("polygon")}}, {{SVGElement("polyline")}}, {{SVGElement("text")}}, {{SVGElement("textPath")}}, and {{SVGElement("tspan")}} elements nested in an {{SVGElement("svg")}}. It doesn't apply to other SVG, HTML, or pseudo-elements.
/* keywords */
fill-rule: evenodd;
fill-rule: nonzero;
/* Global values */
fill-rule: inherit;
fill-rule: initial;
fill-rule: revert;
fill-rule: revert-layer;
fill-rule: unset;
nonzero
evenodd
{{CSSInfo}}
{{csssyntax}}
This example demonstrates how a fill-rule is declared, the effect of the property, and how the CSS fill-rule property takes precedence over the fill-rule attribute.
We define an SVG with two complex shapes defined using the SVG {{SVGElement("polygon")}} and {{SVGElement("path")}} elements. The polygon has the SVG fill-rule attribute set to evenodd and the star-shaped path is set to nonzero, which is the default. To make the lines visible, we set the outline to red using the SVG {{SVGAttr("stroke")}} attribute (we could have alternatively used the {{CSSXRef("stroke")}} property).
<p>Original SVG</p>
<svg viewBox="0 0 220 120" xmlns="http://www.w3.org/2000/svg">
<polygon
points="180,10 150,100 220,40 140,40 210,100"
stroke="red"
fill-rule="evenodd" />
<path
d="M 10,5 l 90,0 -80,80 0,-60 80,80 -90,0 z"
stroke="red"
fill-rule="nonzero" />
</svg>
<p><code>fill-rule: nonzero;</code></p>
<svg viewBox="0 0 220 120" xmlns="http://www.w3.org/2000/svg">
<polygon
points="180,10 150,100 220,40 140,40 210,100"
stroke="red"
fill-rule="evenodd" />
<path
d="M 10,5 l 90,0 -80,80 0,-60 80,80 -90,0 z"
stroke="red"
fill-rule="nonzero" />
</svg>
<p><code>fill-rule: evenodd;</code></p>
<svg viewBox="0 0 220 120" xmlns="http://www.w3.org/2000/svg">
<polygon
points="180,10 150,100 220,40 140,40 210,100"
stroke="red"
fill-rule="evenodd" />
<path
d="M 10,5 l 90,0 -80,80 0,-60 80,80 -90,0 z"
stroke="red"
fill-rule="nonzero" />
</svg>
The above SVG is repeated three times; we've only shown one copy for the sake of brevity.
The shapes nested in the first SVG have no CSS applied. We set the shapes inside the second SVG to use the nonzero value. The third SVG has all its nested shapes set to evenodd.
svg {
border: 1px solid;
height: calc(33vh - 2.5em);
margin-bottom: 10px;
}
p {
margin: 0;
}
svg:nth-of-type(2) > * {
fill-rule: nonzero;
}
svg:nth-of-type(3) > * {
fill-rule: evenodd;
}
{{EmbedLiveSample("Defining the fill rules for SVG elements", "300", "540")}}
With the nonzero value for fill-rule, the "inside" of the shape is the entire shape. The evenodd value defines some space as empty. The first image renders the fill-rule included as an attribute. Declaring the fill-rule in the CSS overrides the attribute values in the second and third images.
{{Specifications}}
{{Compat}}
fill-rule, {{cssxref("clip-rule")}}, {{cssxref("color-interpolation-filters")}}, {{cssxref("fill-opacity")}}, {{cssxref("fill")}}, {{cssxref("marker-end")}}, {{cssxref("marker-mid")}}, {{cssxref("marker-start")}}, {{cssxref("shape-rendering")}}, {{cssxref("stop-color")}}, {{cssxref("stop-opacity")}}, {{cssxref("stroke")}}, {{cssxref("stroke-dasharray")}}, {{cssxref("stroke-dashoffset")}}, {{cssxref("stroke-linecap")}}, {{cssxref("stroke-linejoin")}}, {{cssxref("stroke-miterlimit")}}, {{cssxref("stroke-opacity")}}, {{cssxref("stroke-width")}}, {{cssxref("text-anchor")}}, and {{cssxref("vector-effect")}}