SyntaxStudy
Sign Up
HTML HTML Images In-Depth
HTML Beginner 1 min read

HTML Images In-Depth

HTML Images In-Depth

Images make pages visually engaging. Understanding how to use them correctly matters for performance and accessibility.

Image Formats Compared

FormatBest For
JPG/JPEGPhotographs — small file size, slight quality loss
PNGLogos, graphics, screenshots — supports transparency
WebPModern alternative — smaller than JPG/PNG with similar quality
SVGIcons, logos — infinitely scalable vector format
GIFSimple animations

Responsive Images

Use CSS max-width: 100% or the HTML srcset attribute to serve different image sizes for different screens.

Example
<!-- Basic image -->
<img src="photo.jpg" alt="Mountain landscape" width="600">

<!-- Responsive: always fits its container -->
<img src="photo.jpg" alt="Landscape" style="max-width: 100%; height: auto;">

<!-- srcset: serve different sizes to different screens -->
<img
  src="photo-800.jpg"
  srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1200.jpg 1200w"
  sizes="(max-width: 600px) 400px, 800px"
  alt="Responsive photo">