# .png

> The `.png` (Portable Network Graphics) is an image format that uses lossless compression, maintaining image quality while reducing file size.

## When should I use PNG instead of JPEG?

The lossless image format that retains all the image data, ensuring no quality loss when compressed. It supports transparency and is commonly used for web graphics and images that require high-quality details.

- Topic: Graphics
- Type: format

## Example

Wrong:

```html
<img src="sneaker-cutout.jpg" alt="Red sneaker"
  width="600" height="600">
```

Right:

```html
<picture>
  <source srcset="sneaker-cutout.webp" type="image/webp">
  <img src="sneaker-cutout.png" alt="Red sneaker" width="600" height="600">
</picture>
```

A cutout needs transparency: PNG keeps it losslessly, and WebP keeps it at a smaller size.

## Common mistakes

- Using PNG for photos, making files several times larger than needed.
- Exporting icons as PNG instead of SVG, so they blur when scaled.

## Key points

- PNG is used for images that need transparency or sharp edges, not photos.
- Large PNGs are optimized or also offered as WebP or AVIF.

## Interview questions

### Is PNG lossless?

Yes. PNG compression never loses data, though tools may reduce colors to a palette before saving to make files smaller.

### What is the difference between PNG-8 and PNG-24?

PNG-8 uses a palette of up to 256 colors and is smaller. PNG-24 stores full color, and PNG-32 adds an alpha channel.

## Related cards

- [.jpeg](https://wonderium.dev/engineering/jpeg.md)
- [.webp](https://wonderium.dev/engineering/webp.md)
- [.svg](https://wonderium.dev/engineering/svg.md)
- [Raster Graphics](https://wonderium.dev/engineering/raster-graphics.md)
- [`<picture>`](https://wonderium.dev/html/picture.md)

---

- Level: [Engineering](https://wonderium.dev/engineering.md)
- HTML version: https://wonderium.dev/engineering/png
- Last updated: 2026-11-25
