Menu

1 / 2

PNG, JPG or WebP? A developer's rule of thumb for picking image formats

DEV Community: frontend·Pablo Infante·about 13 hours ago
#OYYE2i2M
#devtofrontend#devto#dev#alpha#lossless
Long article (578 words) — no AI summary yet.
Reading 0:00
15s threshold

Most image-format bugs I see in code review aren't exotic. A logo ships as a 900 KB JPG with fuzzy edges. A hero photo ships as a PNG that weighs more than the rest of the page combined. A product cut-out loses its transparency and shows up on a white box over a dark theme. All three come from the same gap: picking a format by habit instead of by what the pixels are.

Here's the rule of thumb I actually use.

First, know what you're compressing

A 1920×1080 image is 2,073,600 pixels. Stored raw with an alpha channel (4 bytes per pixel), that's 8,294,400 bytes — about 8.3 MB before any compression. Every format below is a different strategy for shrinking that number, and each one is good at a different kind of image.

PNG is lossless. It reproduces every pixel exactly and supports full alpha transparency. It compresses well when the image has large flat areas and repeated patterns — UI, text, diagrams, icons.

JPG is lossy.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.