SVG Vector Lab logo SVG Vector Lab

Transparency and overlapping shapes

Why overlapping SVG shapes get darker: group opacity versus fill-opacity

Trying to fade an icon, but seeing a darker patch where its shapes overlap? First decide what should become transparent: each fill, each shape, or the assembled icon. Those choices are not interchangeable. (object and group opacity, fill opacity)

Fade the assembled icon with group opacity

Save this complete example as group.svg and open it in a browser:

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="160" viewBox="0 0 240 160">
  <title>Two overlapping circles faded as one group</title>
  <rect width="240" height="160" fill="#ffffff"/>
  <g fill="#000000" opacity="0.5">
    <circle cx="90" cy="80" r="50"/>
    <circle cx="150" cy="80" r="50"/>
  </g>
</svg>

Expected observation: both circles and their shared region have the same gray interior. The opaque circles are assembled first, then the group is faded. Use this when a multi-shape icon should behave as one translucent object. Group opacity does not erase differences already inside the artwork. (object and group opacity)

Keep the background rectangle outside the group so it does not fade with the circles.

Compare opacity on each child

Save the second complete example as children.svg:

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="160" viewBox="0 0 240 160">
  <title>Two overlapping circles faded individually</title>
  <rect width="240" height="160" fill="#ffffff"/>
  <g fill="#000000">
    <circle cx="90" cy="80" r="50" opacity="0.5"/>
    <circle cx="150" cy="80" r="50" opacity="0.5"/>
  </g>
</svg>

Expected observation: the shared region is darker than either circle alone. Each translucent circle is composited separately, so the second adds paint over the first. This may be exactly right for overlapping translucent objects, but it is not a uniform fade of their combined silhouette. (object and group opacity)

Compare interior areas, not antialiased edges. Keep geometry, color and background identical while changing only the opacity placement.

Fill-opacity on a group is not a group fade

Try this complete third file:

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="160" viewBox="0 0 240 160">
  <title>Overlapping circles with inherited fill opacity</title>
  <rect width="240" height="160" fill="#ffffff"/>
  <g fill="#000000" fill-opacity="0.5">
    <circle cx="90" cy="80" r="50"/>
    <circle cx="150" cy="80" r="50"/>
  </g>
</svg>

Expected observation: a darker overlap, like the child-opacity example. Here fill-opacity is inherited by the circles and affects each fill operation. It does not flatten their combined silhouette before fading it. A child can override the inherited fill-opacity value. (fill opacity)

Use numeric values from 0 to 1 in these experiments: 0 is transparent, 1 is fully opaque, and 0.5 is halfway. Opacity is not ordinarily inherited. Its effect on a parent still applies to the rendered descendants. (the opacity property)

Parent and child opacity both matter

In group.svg, add opacity="0.5" to the first circle while leaving the group's opacity="0.5". Expected observation: the first circle's exposed interior becomes lighter than the second circle's exposed interior. Setting a child to opacity="1" does not cancel a parent's fade. (object and group opacity, the opacity property)

Do not multiply every number in a complex overlapping icon and assume that describes every pixel. Inspect the assembled result, especially where children overlap.

Fade the fill while keeping a solid stroke

Use fill-opacity when the interior should fade but the outline should remain solid:

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="160" viewBox="0 0 240 160">
  <title>Translucent fill with a solid outline</title>
  <rect width="240" height="160" fill="#ffffff"/>
  <rect x="40" y="30" width="160" height="100"
        fill="#000000" fill-opacity="0.25"
        stroke="#000000" stroke-opacity="1" stroke-width="12"/>
</svg>

Expected observation: a light gray interior and black outline. Replacing fill-opacity="0.25" with opacity="0.25" fades the complete rectangle, including its stroke. Conversely, stroke-opacity targets only the stroke paint. An ancestor's opacity can still fade both. (object and group opacity, fill opacity)

For outline geometry, see the SVG strokes guide. For choosing paint and debugging CSS color rules, see change SVG color.

Check the source you actually export

Before using the finished icon:

  1. Keep an untouched copy of the original SVG.
  2. Locate opacity, fill-opacity and stroke-opacity in the source, including surrounding groups and style declarations. If an attribute edit seems ineffective, inspect the applied CSS as well. (presentation attributes)
  3. Decide whether the fade belongs on a complete group or on an individual paint operation.
  4. Open the exact exported file, not just the editor preview. Compare shape boundaries, overlap interiors and outlines with the original.
  5. In a test copy, change the background rectangle to #202020. Repeat the comparison. The background in these examples is deliberately painted, so changing only the page behind them will not change it.
  6. If a tool rewrites the structure or paint, inspect that exported source and test again. Do not assume every editor preserves every SVG feature.

The practical rule: use group opacity for a fade of the assembled icon, fill-opacity for its fills, and child opacity when each object should remain independently translucent. (object and group opacity, fill opacity)

References