Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

Where Did the White Background Go?

Two purple folder icons looked identical on a white background. On a dark toolbar, one blended in. The other came with a white square. Both PNGs were 24 × 24 px. The difference came from a single rectangle. Sa

Where Did the White Background Go?

Two purple folder icons looked identical on a white background. On a dark toolbar, one blended in. The other came with a white square.

Both PNGs were 24 × 24 px. The difference came from a single rectangle.

Same icon, one extra rectangle

The test uses two SVGs with the same folder paths and the same viewBox. The first sat on a white page. The second starts with this rectangle before the folder paths so it would paint behind them.

<rect width="24" height="24" fill="#fff"/>

Both were exported with Inkscape 1.4 using --export-background-opacity=0. That setting makes otherwise unpainted areas transparent. The rectangle still paints white because it is part of the SVG.

The corners tell the story

SVG variant Alpha at all four corners On a dark toolbar
White page behind the SVG 0 The toolbar shows through
White rectangle inside the SVG 255 A white square surrounds the folder

Two purple folder icons look alike on white. On a dark toolbar the transparent icon blends in, while the other has a white square. Their corner alpha values are 0 and 255

Both PNGs were exported at 24 × 24 px. The icons are enlarged here so the difference is easy to see.

Check the PNG itself

Point a pixel inspector at a corner you expect to be empty. With Pillow, you can print the RGBA values without opening an editor.

from PIL import Image

with Image.open("folder-transparent.png") as image:
    rgba = image.convert("RGBA")
    print(rgba.getpixel((0, 0)))

The fourth value is alpha. In this test it was 0 for the transparent corner and 255 for the white one. Checking the alpha matters because a pixel can carry white RGB values and still be fully transparent.

Put the exported file on the actual toolbar color, too. The corner check tells you whether that pixel is transparent. The toolbar reveals whether the icon works in context.

A quick check in IconVectors

Use the Preview Panel to switch between light and dark backgrounds. For PNG assets, the Explorer’s batch export creates images with transparent backgrounds wherever the SVG leaves pixels unpainted. If the icon needs a white backing on every theme, keep that rectangle in the artwork.

IconVectors Preview Panel · IconVectors batch bitmap export

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.