PerfectVector
Studio
By Irene Kim

SVG Fill Opacity vs. Opacity on Overlapping Shapes

See why two semitransparent SVG shapes darken where they overlap. Choose fill opacity, object opacity, or group opacity with a tested example.

5 min read
On this page

In SVG, fill-opacity fades the interior paint and lets you keep a solid outline. opacity fades the element as a whole, including its fill and stroke. To fade a stack of shapes together, put opacity on their shared <g>. The renderer combines the shapes first, then applies the fade to that combined result. SVG 2 rendering and object opacity

The difference shows up when two pieces overlap. Two circles each set to half opacity make a denser overlap. Two opaque circles inside one group at half opacity produce a uniform silhouette if the circles share the same color.

Which SVG opacity property should you use?

Fill opacity controls the opacity of the paint inside a shape. The stroke has a separate stroke-opacity setting. Apply element opacity when the border and interior should fade together. Apply group opacity for a fade that treats a multi-piece icon as a unit. SVG 2 fill and stroke paint properties

What you wantSet thisWhat to look for
Light interior and solid borderfill-opacity=".5" on the shapeThe background shows through the fill, while an opaque stroke stays strong.
One shape that fades as a unitopacity=".5" on the shapeBoth the fill and the stroke fade.
Two shapes with a darker overlapopacity=".5" on each shapeThe overlap receives two layers of paint.
One silhouette at uniform opacityopacity=".5" on a parent groupThe already-rendered group receives one fade.

Render three versions of the same pair of circles

Save this as opacity.svg and open it on a light background. The left pair uses fill opacity. The middle pair uses opacity on each circle. The right pair uses a single opacity setting on their parent.

<svg xmlns="http://www.w3.org/2000/svg" width="300" height="74" viewBox="0 0 300 74">
  <g fill="#086c75" fill-opacity=".5">
    <circle cx="28" cy="36" r="22"/>
    <circle cx="56" cy="36" r="22"/>
  </g>
  <g fill="#086c75" transform="translate(100 0)">
    <circle cx="28" cy="36" r="22" opacity=".5"/>
    <circle cx="56" cy="36" r="22" opacity=".5"/>
  </g>
  <g fill="#086c75" opacity=".5" transform="translate(200 0)">
    <circle cx="28" cy="36" r="22"/>
    <circle cx="56" cy="36" r="22"/>
  </g>
</svg>
Three pairs of SVG circles showing denser overlaps with fill or object opacity and a uniform silhouette with group opacity
The original SVG example rendered over white. Each circle is the same size and color. Only the scope of the opacity changes.

In our 300 × 74 pixel transparent render, the center alpha of the first two pairs was approximately 75%, compared with 50% in the group-opacity overlap. Alpha measures how opaque a pixel is. In the first two pairs, the source-over formula for the overlap is 0.5 + 0.5 × (1 − 0.5) = 0.75. In the third pair, the opaque circles are combined before the group gets its single half-opacity fade. W3C simple alpha compositing

The left and middle examples look alike because the circles have no stroke. Add stroke="#173340" stroke-width="4" to the first circle in each pair. On the left, the first circle's uncovered stroke stays solid. In the middle, the first circle's stroke fades with the fill.

Fix an overlap that darkens unexpectedly

First check whether fill-opacity is set on a parent group. The property is inherited. Putting fill-opacity=".5" on a group passes the setting to the child fills, which can still overlap as separate layers.

If you need one uniform fade, remove the per-child fade and set opacity=".5" on the group. Test the output over the actual background, because the composite color will depend on that background. If the SVG looks different only after export or import, the SVG color export troubleshooting guide shows how to separate opacity from color profile and paint-reference issues. For an outline that gets buried under a fill, inspect SVG paint order.

Group opacity changes the rendered paint. It does not merge paths. Keep the group for editability or use a geometry operation if the deliverable needs one actual outline.

FAQ

Does fill-opacity affect an SVG stroke?

No. It affects the fill paint. Use stroke-opacity for a separate stroke fade, or opacity on the shape to fade both.

Why is the overlap between two 50% opacity shapes darker?

Each shape is drawn over the pixels already underneath it. With two same-color layers at 50% opacity, the overlap reaches 75% alpha in the simple source-over case.

Can I set fill-opacity on a group?

Yes. Its descendants can inherit that fill opacity. Use opacity on the group when you want to render the group as a whole and fade the result once.

Start with separate editable shapes

PerfectVector can turn flat raster artwork into editable vector paths.

If all you have is a PNG or JPG, trace the artwork into editable paths and inspect the shapes that should overlap. Set their SVG opacity after you confirm which regions should stay distinct.

Sources

  1. W3C SVG 2 — Object and group opacity — Explains the compositing scope of element and group opacity.
  2. W3C SVG 2 — Fill paint opacity — Defines the fill painting operation and inheritance.
  3. W3C Compositing and Blending — Simple alpha compositing — Defines the source-over calculation used in the overlap example.

More from the blog

PerfectVector

Start with a cleaner SVG
that is easier to edit

Vectorize and inspect previews for free, with no daily limit.