FE Interview Hub
CSSBasic

When should you use JPG, PNG, WebP, or SVG in frontend development?

AI Practice

Format Comparison

Format Compression Transparency Animation Best For
JPG Lossy Photos, complex color images
PNG Lossless Icons needing transparency, screenshots
WebP Lossy / Lossless General modern replacement format
SVG Vector Logos, icons, simple illustrations

JPG (JPEG)

  • Pros: Small file size, great for photographic images
  • Cons: Lossy compression; no transparency; artifacts at high compression
  • Use for: Background images, product photos, photographs

PNG

  • Pros: Lossless, supports transparency (alpha channel)
  • Cons: Usually larger than JPG
  • Use for: UI elements needing transparency, screenshots, text-heavy images

WebP

  • Pros: ~25–35% smaller than JPG, supports transparency and animation, both lossy and lossless
  • Cons: Not supported by older browsers (IE)
  • Use for: Modern projects as a universal replacement for JPG and PNG
<!-- Use <picture> for graceful degradation -->
<picture>
  <source srcset="image.webp" type="image/webp">
  <img src="image.jpg" alt="Example image">
</picture>

SVG

  • Pros: Scalable vector — never loses quality at any size; styleable with CSS; small file size
  • Cons: Not suitable for complex photographic images
  • Use for: Logos, icons, illustrations, animated graphics

Recommendations

  • Photos → WebP (preferred), then JPG
  • Transparency needed → WebP (preferred), then PNG
  • Icons / Logos → SVG
  • Modern projects (no IE support needed) → Default to WebP

✦ AI Mock Interview

Type your answer and get instant AI feedback

Sign in to use AI scoring