Course contentsShow
← Web Development
Lesson 1241 of 2,98222. Responsive Images and MediaFree lesson

PNG: Lossless Compression and Transparency

Learn when to use PNG for images requiring transparency or lossless compression, and understand PNG-8 vs PNG-24.

PNG: Lossless Compression and Transparency

You'll learn when to choose PNG format and understand the difference between PNG-8 and PNG-24.

What PNG Does Differently

Unlike JPEG's lossy approach (which throws away detail to shrink file size), PNG uses lossless compression. Think of it like zipping a file — when you unzip it, you get back exactly what you started with. Every pixel preserves its exact color information, making PNG perfect for images where precision matters.

PNG's other superpower? Transparency. While JPEG forces you to have a solid background, PNG can have see-through areas that let your page's background show through.

When to Use PNG

Choose PNG for:

  • Logos and icons with sharp edges and solid colors
  • Text within images that needs to stay crisp
  • Graphics with transparency like badges or overlays
  • Screenshots where clarity matters more than file size
  • Simple illustrations with limited colors

Avoid PNG for photographs — JPEG will give you much smaller files.

PNG-8 vs PNG-24: The Key Distinction

PNG-8 supports up to 256 colors (like GIF). It's excellent for simple graphics, icons, and illustrations with limited palettes. Smaller file sizes, but color limitations.

PNG-24 supports millions of colors (true color). Use it when you need both transparency and complex gradients or photographic elements. Larger files, but no color compromise.

Both support transparency, but PNG-24 offers smoother, more sophisticated transparency with varying opacity levels (alpha channel), while PNG-8 transparency is more basic.

Key Takeaway: Use PNG when you need pixel-perfect quality or transparency — PNG-8 for simple graphics with few colors, PNG-24 for complex images requiring full color range and sophisticated transparency.