Content · Web Development · HTML

HTML Image Formats: PNG, JPEG, SVG, WebP, and AVIF

Different image formats make different tradeoffs. JPEG works well for many photographs, PNG supports lossless detail and transparency, SVG is useful for vector graphics, and WebP or AVIF can reduce file sizes.

1 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

Different image formats make different tradeoffs. JPEG works well for many photographs, PNG supports lossless detail and transparency, SVG is useful for vector graphics, and WebP or AVIF can reduce file sizes. Think about what the picture adds to the story, not just whether it looks nice on the screen.

What You Need to Know


The picture element can offer modern formats with an img fallback. Format support and image quality vary, so choose after viewing real results rather than relying only on the extension.

Pictures can make a page much easier to understand, but they are useful only when the file loads and the important meaning is also available as text.

Example: See It in Action


Add this example to the appropriate part of a practice HTML page. Read each line before you open the page in your browser.

This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.

<picture>
    <source srcset="images/fox.avif" type="image/avif">
    <source srcset="images/fox.webp" type="image/webp">
    <img src="images/fox.jpg" alt="Fox sitting in grass" width="800" height="600">
</picture>

Let’s Understand the Example


  • Img displays an image. Src chooses the file and alt provides a useful text alternative.
  • Picture lets the browser choose between alternative image sources while keeping an img fallback.
  • Srcset provides alternative image files for different screen sizes or pixel densities.
  • Type changes the kind of input, script, resource or button, depending on the element.
  • Src tells the browser where to find an image or other embedded resource.
  • Alt supplies a text alternative for an image. Empty alt is appropriate for purely decorative images.

An image appears only if its file path is correct. If it is informative, its alt text should share the same useful meaning; if it is decoration, empty alt text is often right.

What Should You See?


If the image file is available, the picture appears in the page. If not, the browser may show a broken image or fallback text. The example alt text is “Fox sitting in grass”. Check that the text alternative fits the picture’s purpose.

Cover the picture and read the surrounding text aloud. If essential information has disappeared, add a useful text alternative or nearby explanation.

Try It Yourself


  1. Export the same photo in two formats and compare visible quality and file size.
  2. Save your changes, open or refresh the page, and compare the result with the original example.
  3. Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.

Common Beginner Mistakes


  • Using a huge PNG photograph when a compressed photo format would load much faster.
  • Never guess at an image description. Write alternative text that matches the picture and its purpose on this page.

Key Takeaways


  • Different image formats make different tradeoffs.
  • Img displays an image. Src chooses the file and alt provides a useful text alternative.
  • The picture element can offer modern formats with an img fallback. Format support and image quality vary, so choose after viewing real results rather than relying only on the extension.
Share this resourceSend this page to someone who may find it useful.