PNGToolbox

Transparency

Alpha channels, mattes and ugly edges: why transparent PNGs go wrong

Transparency is a fourth channel with its own rules. Get the matte wrong and a cutout looks perfect on white and broken on dark. Here is what is actually happening.

By PNGToolbox Editorial Published 2026-10-22 Last reviewed 2026-10-22 How we test

At a glance

  • Alpha is a separate, unassociated channel: zero means fully transparent, the maximum sample value means fully opaque, and PNG deliberately does not premultiply it.
  • Colour types 4 and 6 carry a real alpha channel; colour types 0, 2 and 3 use a tRNS chunk for one transparent colour or a per-palette alpha table.
  • Compositing is alpha x foreground + (1 - alpha) x background, computed on intensity samples rather than gamma-encoded ones. PNG defines the foreground and the mask, never the background.
  • Converting a transparent image to JPG does not hide the transparency: our test put transparent pixels 0.12 to 0.36 levels from pure white on average, which reads as a hard edge.
  • Halos are a colour problem, not an alpha problem. The semi-transparent pixels around a cutout still carry the background they were matted against.
  • Alpha is 8 or 16 bits and always shares the sample depth of the colour channels in the same image.

What an alpha channel actually stores

An alpha channel is a coverage value, not a colour. In an 8-bit PNG it holds 0 to 255; in a 16-bit PNG, 0 to 65535. "An alpha value of zero represents full transparency, and a value of 2^sampledepth - 1 represents full opacity", with everything between meaning partially transparent — pixels that get blended with whatever is behind them.

PNG's choice not to premultiply is deliberate and it is the single fact that explains most transparency bugs. The specification says samples "are not premultiplied by the alpha value assigned to the pixel. This rule is sometimes called 'unassociated' or 'non-premultiplied' alpha", and justifies it in the same sentence: an image editor can take a PNG and change its transparency easily. A premultiplied pixel — one whose colour values have already been scaled by its own alpha — is, in the spec's words, "already composited against a black background". You cannot undo that cleanly. You can only guess at the original colour.

That gives PNG its two useful properties: transparency is editable after the fact, and a colour that happens to be stored under a transparent pixel is still a real colour that can be revealed later. It also creates the situation described in the next three sections, where a colour survives inside pixels nobody can see and then reappears as a fringe when the image is composited somewhere new.

How PNG records transparency, by colour type

Only two of PNG's five image types have a true alpha channel. The rest encode transparency as a special case, and the difference matters when you edit the file:

Colour type Image type How transparency is stored Limitation
0 Greyscale tRNS names one grey sample value that becomes fully transparent Every other pixel is fully opaque
2 Truecolour tRNS names one RGB value that becomes fully transparent No partial transparency anywhere; the value is exact, so a colour close to it stays opaque
3 Indexed-colour tRNS supplies one alpha byte per palette entry, where "0 is fully transparent, 255 is fully opaque, regardless of image bit depth" At most 256 alpha values, one per palette entry
4 Greyscale with alpha A real second channel beside each sample Two channels per pixel instead of one
6 Truecolour with alpha A real fourth channel beside R, G and B Four channels per pixel instead of three

Two tRNS details cause real damage. For indexed images the chunk may be shorter than the palette, and any entry it does not cover is assumed fully opaque — so a tool that trims the chunk silently changes what is transparent. And for greyscale and truecolour images the transparent value is matched exactly: anti-aliased text on a background you chroma-keyed will leave an opaque halo one shade off your key colour. A tRNS chunk "shall not appear for color types 4 and 6", because those types already carry transparency in every pixel.

The practical read: if you need partial transparency, you need colour type 4 or 6, which means the file carries two or four channels of data per pixel whether or not most of the image is opaque. An indexed PNG with tRNS is far cheaper — one byte per pixel plus a small table — but its transparency is categorical. Pixels are opaque or transparent or one of the palette's alpha values, never a smooth gradient.

Straight versus premultiplied alpha

Straight alpha (PNG's default) keeps colour and coverage independent: RGB is the colour the pixel would have if it were fully opaque, and A says how much of it to show. Premultiplied alpha multiplies RGB by A at storage time, which makes compositing cheaper — the standard "over" operation is a single add instead of a multiply-add per channel — and is why renderers, video compositing tools and graphics APIs often work in premultiplied space.

Both encodings describe the same pictures, but converting between them is lossy in one direction, and asymmetrically so:

  1. Premultiplied to straight divides each colour sample by its alpha and rescales to the bit depth, and "if the alpha value is zero, output black (zeroes)". Fully transparent pixels have no recoverable colour, so all of them become black — or whatever else a tool decides to invent.
  2. Straight to premultiplied multiplies instead. That is exact per pixel but throws away precision: at alpha 3/255 a colour channel has four representable values left, so a soft shadow quantises into a handful of steps.

The failure mode shows up after a round trip. A logo with a soft glow pushed through a pipeline that premultiplied and unpremultiplied it comes back with a grey haze in the faintest parts, because the colour that used to sit under an alpha of 2/255 is now a quantised guess. Writing premultiplied data into a PNG without the dividing step produces a file that looks correct on screen and wrong the moment someone paints a different background behind it.

If you cannot tell which convention a tool uses, run one test. Fill a canvas with pure red, draw a soft-edged white shape, save as PNG, and sample a pixel on the edge: high stored red with low alpha means straight alpha; red falling in proportion to alpha means premultiplied.

The matte problem: where white fringes come from

Every image without an alpha channel has to be flattened onto something. JPG is that case by definition — it has no alpha channel at all — so exporting a transparent PNG to JPG must pick a background colour, and white is the usual default. Our benchmark measured what that costs: for both transparent test images, the transparent pixels came out of the JPG encode "0.12 to 0.36 levels away from pure white on average". On a white page that is invisible. On anything else it is a pale rectangle with a hard edge exactly where the alpha ended.

That is the first fringe: the area fringe, visible on every background that is not the matte colour. The second one is subtler and survives the conversion back to PNG.

Consider a cutout prepared by flattening a transparent product shot onto white and then removing the background with a colour-based selection. The pixels that were semi-transparent — the ones along a feathered edge — were blended with white before the selection tool ever saw them. If the tool only decides "background or not background", those pixels become opaque pixels whose colour is white mixed with the product. Ship that PNG on a dark blue page and every soft edge glows pale. Nothing is wrong with the alpha channel; the alpha channel was never the problem.

Compare that with what PNG preserved in the same benchmark: for both RGBA sources, transparent pixel counts matched exactly, and every alpha value came back within 1/255 of the original — 229,211 transparent pixels of 640,000 for the logo, and 1,056,057 of 1,960,000 for the product cutout. PNG kept the mask perfectly in both directions. The damage happened upstream, in whatever produced the matte colour that the edge pixels still carry.

Soft edges, halos and defringing

Once you know the fringe is colour trapped inside low-alpha pixels, the fixes get obvious and ordered.

  • Keep colour and alpha together from the start. Cut out from the original unflattened source. If the only file you have is a JPEG of the product on white, you are reconstructing, not extracting — expect to spend time on the edge.
  • Refine the mask, do not just threshold it. A hard threshold turns feathered pixels binary and leaves the matte colour attached to whatever survives. Selecting a slightly wider edge and feathering inward replaces contaminated pixels with a blend the compositor can work with.
  • Use a defringe or "remove white matte" step. These operations subtract a scaled copy of the light background from edge pixels, which is the right idea mathematically and easy to over-apply; run it at low strength and check the result on both a white and a dark background.
  • Set the colour of fully transparent pixels deliberately. The specification's encoder guidance is explicit here: transparent pixels "should all be assigned the same color value for best compression", and "the colors assigned to transparent pixels should be reasonable background colors whenever feasible". This is also exactly what oxipng's --alpha option does at a purely mechanical level, which its own documentation flags as technically lossy: it rewrites colour values under pixels you cannot see.
  • Check the alpha, not the preview. Editors that show a checkerboard are telling you which pixels are transparent, not how transparent they are. Any pixel between 1 and 254 is a candidate fringe, and a soft-edged cutout has thousands of them.

The compressed-size angle is worth knowing too. The specification notes that "alpha is typically either zero or one for the vast majority of pixels in an image" and uses that as an argument for fast compositing paths. It applies to encoding as well: a hard-edged mask is nearly free in bytes, while a feathered mask turns a fourth channel into a near-photographic plane that DEFLATE cannot predict. Feathering everything as a habit costs real size on products, avatars and icon sets.## 8-bit versus 16-bit alpha

The alpha channel uses the same sample depth as the colour channels it sits beside, so an 8-bit PNG has 256 alpha levels per pixel and a 16-bit PNG has 65,536. Both are legal for colour types 4 and 6; indexed images are restricted to 8-bit alpha values in tRNS anyway.

Where the difference shows is smooth coverage over a large area: a soft drop shadow, glass, smoke, a vignette fading to nothing. At 8 bits the steps between adjacent alpha values are 1/255, so a shallow ramp across 900 pixels changes roughly three levels per step — visible as banding on a dark background, and worse after any resampling or compositing that stretches the ramp. A 16-bit alpha plane cuts those steps by a factor of 256.

Where it does not show is anything with hard edges. A logo mask of 0s and 255s gains nothing from 16 bits, and the cost is real: 16-bit RGBA is eight bytes per pixel before compression, double the 8-bit version, and the extra precision is often false — interpolated by an editor from 8-bit data in the first place. Masters and print-bound art can reasonably be 16-bit; anything destined for a screen should be 8-bit. The screen is 8-bit per channel anyway.

Resizing and compositing transparent images

Scaling is where straight alpha gets punished. A resize filter treats each channel as an independent plane and averages neighbours, so around a soft edge the colour plane blends the product's colours with whatever colour the transparent pixels contain, while the alpha plane blends coverage. The two no longer describe the same pixel: you get a rim of colour that belongs to neither the object nor the background.

The standard fix is to premultiply, resize, then unpremultiply — the compositing operation is linear in premultiplied space, which is exactly what an interpolation filter assumes. Adobe's tools, GIMP's "resize with premultiplied alpha" options and most libraries that expose an alpha-aware resize all do this. If you resize a straight-alpha PNG in a tool that does not, expect a one- or two-pixel dark or light rim; it is most obvious on a logo scaled down by a non-integer factor.

Resampling kernels matter as much as alpha handling. In our own resampling measurements, upscaling a hard edge 4x left bilinear and nearest-neighbour with no overshoot at all, while bicubic overshot the edge by 10/255 on each side and Lanczos by 15/255 — a visible halo around every high-contrast boundary, which is precisely the artefact people blame on "transparency". Downscaling showed the mirror-image problem: against an area-average reference, nearest-neighbour left a halftone pattern with 6.85 standard deviations of noise where an ideal downscale leaves only 1.2. The full table is in the screenshot and text guide.

There is also a straightforward ordering rule for the whole pipeline: crop, scale, adjust colour, and only then apply or refine the mask. Working on the mask last means the expensive edge work is not resampled afterwards, and it avoids the situation where a resize quietly recontaminates an edge you just cleaned.

A pre-ship checklist for transparent PNGs

Work through this before a cutout goes anywhere near a client, a marketplace or a store listing. Every item takes seconds and catches a different class of bug:

  1. View the file on two backgrounds. A white page and a dark page, side by side. Fringes that survive both are in the data, not in the preview.
  2. Check that transparent really is transparent. In a file manager or editor, transparency should show as a checkerboard, not as white, black or a solid colour block. A "transparent" PNG that displays on white has been flattened.
  3. Sample a few edge pixels. Look for any pixel with alpha between 1 and 254 whose colour matches an old background rather than the object. Those are the pixels that will halo.
  4. Confirm the colour type. An indexed PNG with a tRNS chunk cannot hold partial transparency; if the design needs a soft edge, the file has to be colour type 4 or 6.
  5. Resize once, from a premultiplied copy. Never iteratively rescale the same cutout; each pass compounds edge error on a file you cannot reconstitute.
  6. Keep a master. Save the layered or 16-bit version somewhere, because the exported PNG is a delivery format, not an archive. Editing it later means editing its current matte.
  7. Test the conversion target before you ship. If the consumer is a JPG-only upload form, a print pipeline or an old desktop tool, the matte colour is your decision to make deliberately rather than the tool's.
  8. Re-check the alpha after any conversion. Our benchmark shows PNG preserves it exactly, but that is a property of PNG, not of every tool that writes a .png file.

If the file in your hand is a WebP with a transparent background and the destination wants PNG, the transparent-tool flow in the converter decodes and re-encodes without touching the alpha plane, and the transparent-background guide covers the cases where the background itself has to be removed. When the question is which format should carry the transparency in the first place — PNG, WebP, AVIF or JPEG XL — that comparison, with current browser support, is here.

Convert WebP files to PNG or JPG — in your browser

Batch conversion, ZIP download, transparency kept. No upload.

Open the converter

Sources

  • PNG Specification, Third Edition — alpha representation and unassociated alpha, tRNS semantics, compositing equation, encoder guidance on transparent pixel colour — https://www.w3.org/TR/png-3/
  • MDN: Image file format guide — JPEG has no alpha channel; alpha support in AVIF, WebP and JPEG XL — https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Formats/Image_types
  • WebP compression documentation (Google) — lossy RGB with a lossless 8-bit alpha channel — https://developers.google.com/speed/webp/docs/compression
  • Oxipng documentation — --alpha rewrites the colour of fully transparent pixels and is flagged as technically lossy — https://github.com/oxipng/oxipng
  • Measured alpha and matte results: study-a-format.csv, study-c-resize.csv — ./assets/bench/