How to compress images and keep transparency

JPEG cannot store transparency at all. Everything else about this problem follows from that one fact — including the black box around your logo.

What keeps transparency

PNG
Yes. Full 8-bit alpha, 256 levels of opacity.
WebP
Yes, in both lossy and lossless modes. Typically 25% smaller than PNG.
AVIF
Yes, and smaller again — but browsers cannot write it.
GIF
Binary only. A pixel is fully opaque or fully transparent, hence the jagged edges.
JPEG
No. None. Transparent pixels must become a solid colour.
Best for the web
WebP. Same alpha channel as PNG, meaningfully smaller.

Getting it right

  1. Step 1: Confirm you actually need transparency

    A white background is not transparency. If the image will always sit on white, a JPEG is far smaller and looks identical. Transparency is only needed when the background behind the image can vary.

  2. Step 2: Choose PNG or WebP

    WebP for the web — same full alpha channel, typically 25% smaller than PNG. PNG when the file must open in older desktop software, or when a system rejects WebP uploads.

  3. Step 3: Reduce the dimensions rather than the quality

    Lossless formats respond to pixel count, not to a quality slider. Halving the width and height is the reliable way to shrink a transparent PNG — a logo displayed at 200 pixels does not need to be 1200.

  4. Step 4: If you must flatten, choose the colour deliberately

    Converting to JPEG means picking what fills the transparent areas. Choose it yourself to match where the image will sit, rather than letting an encoder default to black.

Details worth knowing

The black box around your logo

This is the single most common transparency problem, and its cause is simple. JPEG has no alpha channel, so when a transparent PNG is converted every transparent pixel must become an actual colour — and many tools fill them with black without mentioning it.

The result is a logo inside an unwanted dark rectangle. It is not a bug in your file; it is JPEG doing the only thing it can with data it cannot represent.

The fix is either not to convert to JPEG, or to flatten deliberately onto a colour you have chosen. The PNG to JPG tool on this site defaults to white and gives you the switch, because that choice belongs to you rather than to an encoder's default.

Halo edges, and why they happen

A softly anti-aliased edge is stored as partially transparent pixels — a logo's outline might be 70% opaque black fading to 0%. Those pixels also carry a colour, and what that colour is matters when the image is composited.

If a graphic was created against a white background, its semi-transparent edge pixels carry white. Place it on a dark background and that white shows through as a pale halo. The reverse produces a dark fringe on light backgrounds.

Two fixes. Export from your editor with a matte colour matching where the image will actually sit. Or, better, work with genuinely unmatted transparency so the edge pixels carry the subject's own colour rather than a background you assumed.

Why GIF transparency looks jagged

GIF supports only binary transparency: each pixel is either fully opaque or fully invisible. There is no partial opacity, so there is no way to represent a smooth anti-aliased edge.

The result is the stair-stepped outline familiar from 1990s web graphics, and it is unavoidable in that format. PNG's 8-bit alpha exists precisely to solve it, and WebP inherits the same capability.

PNG-8 has the same limitation for the same reason — reducing to a palette usually reduces transparency to binary as well. If a "PNG optimiser" makes your soft edges jagged, it converted to PNG-8.

Making a transparent image smaller

Because PNG is lossless, the quality slider does nothing for it. What does work:

  • Reduce the dimensions. The single biggest lever. Logos are routinely five times larger than they are displayed.
  • Convert to WebP. Same alpha channel, typically 25% smaller losslessly, and smaller again in lossy mode.
  • Strip metadata. Small, but meaningful on small files.
  • Consider SVG. For logos and icons made of shapes rather than photographs, vector is smaller and sharp at every size.

When you do not need transparency at all

A great many transparent PNGs on the web sit permanently on a plain white background, where they could be JPEGs at a fraction of the size and look identical.

Transparency is only worth its cost when the backdrop behind the image can change — a logo used on multiple background colours, a product cut-out over varying page sections, an overlay above a photograph. If the background is fixed and known, flatten it and use a lossy format.

Do it here instead

These run in your browser on any device, so nothing is uploaded and there is nothing to install.

  • Compress PNG

    Lossless by default, with transparency carried through untouched.

    Open the tool
  • Compress WebP

    Re-encode existing WebP files, or convert JPEG and PNG into WebP.

    Open the tool
  • PNG to JPG

    For photographs stored in the wrong container. Transparency is flattened deliberately.

    Open the tool
  • WebP to PNG

    When software refuses WebP. Expect a larger file — that is the trade.

    Open the tool

Questions

Frequently asked questions

Every answer below is present in the page source, expanded, so it can be read without opening anything.

Does compressing a PNG remove transparency?

No, not if the output stays PNG or WebP — both carry a full alpha channel and it is copied across untouched. Transparency is only lost if you convert to a format that cannot store it, which in practice means JPEG.

Why does my logo have a black background after converting to JPG?

Because JPEG has no alpha channel, so every transparent pixel had to become a colour, and the tool chose black. Either keep the file as PNG or WebP, or flatten deliberately onto a colour you pick.

Is WebP better than PNG for transparency?

For the web, yes. WebP carries the same 8-bit alpha channel and is typically 25% smaller losslessly, with support in every current browser. Keep PNG when the file must open in older desktop software.

How do I make a transparent PNG smaller?

Reduce its pixel dimensions — that is the main lever, since PNG is lossless and ignores quality settings. Then convert to WebP for roughly another 25%. For logos made of simple shapes, SVG is smaller still.

Why does my transparent image have a white edge?

Its semi-transparent edge pixels carry white, because it was created against a white background. Placed on a dark background, that white shows through as a halo. Export with a matte colour matching the destination, or use genuinely unmatted transparency.

Should I use GIF for transparency?

No. GIF supports only fully-on or fully-off transparency, so anti-aliased edges come out jagged. PNG and WebP both offer 256 levels of opacity and handle soft edges properly.

From the blog

Related reading

More background from the blog.

  • Image Formats

    PNG vs JPEG: When to Use Each, With the File Sizes to Prove It

    PNG stored the same photograph in 1274.1 KB where JPEG needed 67.5 KB — nineteen times larger. On a flat graphic PNG won. On a smooth gradient PNG lost to JPEG by a factor of two, which surprises most people.

    9 min read

  • Image Formats

    WebP vs JPEG: Which Should You Use, and When JPEG Still Wins

    WebP produced a 27.0 KB file against MozJPEG's 41.1 KB on the same photograph at slightly higher measured fidelity — 34% smaller. It also produced a larger file than JPEG on random noise. The advantage is real and content-dependent.

    9 min read

  • Practical Guides

    How to Compress Images for a Website Without Wrecking Them

    Resize before you compress. Measured on one photograph: half the width at quality 80 produced a 16.4 KB file, while full width at quality 40 produced 20.6 KB and looked far worse. The order of operations matters more than the settings.

    8 min read