How these pages use images
Every example in this section follows the same rules, and the pages explain why as they go:
- Every
<img>has analt. It is empty only when the image is decoration. - Every content image has
widthandheight, so the browser can reserve its space before the file arrives. - Responsive images are markup:
srcsetandsizes, or<picture>when a format or a crop needs to change. - Loading follows position. Images below the fold load lazily; the hero image never does.
- SVG for drawings, raster formats for photographs, and no text baked into a raster image.
- The cheapest image is the one you never send. Every image should earn its bytes.
The CSS in these pages follows the CSS section's house style. Every byte count quoted comes from a real file, encoded by the site's own build script.
The pages
- 01What an image costs
Why images dominate page weight, the question to ask first, raster and vector, pixel math, CSS pixels and device pixels, and content versus presentational images.
- 02Raster formats
Lossless and lossy compression; GIF, JPEG, PNG, WebP, AVIF and JPEG XL; transparency, animation, and a format decision tree.
- 03SVG and vector images
SVG as markup, three ways to put it on a page, styling it with
currentColor, accessible SVG, icon systems, and optimization. - 04Images in HTML
The parts of
<img>,<figure>,srcsetandsizes, and<picture>for formats, crops and color schemes. - 05Images in CSS
Backgrounds, gradients,
image-set(), list markers, masks and borders,object-fit, and when an image belongs in CSS at all. - 06Fluid and responsive images
The fluid baseline, reserving space against layout shift, resolution switching and art direction, and a worked
sizesexample. - 07Images for people
Alt text that does its job, images that fail, users' settings, and images across languages and cultures.
- 08Image performance
Less data, less often, when needed, from nearby: optimizing, loading, preloading, caching, CDNs, and measuring the result.
Films
Three narrated films go with these pages.
- Every Pixel Has a Price (9 min), beside pages 01 and 02: pixel math, lossy and lossless, and choosing a format.
- Which Image Did the Browser Pick? (8 min), beside pages 04 and 06: how
srcset,sizesand<picture>become one download. - The Hero Comes First (7 min), beside page 08: the fold, priority, lazy loading, layout shift and caching.