Dropping an <img> into a page with a valid src is trivial. Doing images well is not — there are close to 927 things worth (and sometimes necessary) doing that routinely get skipped.
Markup and semantics
- Write
alttext in sentence format that describes what the image depicts. - Wrap the image in
<figure>and add<figcaption>when visible accompanying text is wanted. - Reach for
<picture>with multiple<source>elements to serve different source images per screen size or condition, or to deliver next-gen formatted images. - Always set
widthandheightso the layout reserves the right space before load — this applies even when the rendered width is fluid.
Formats, sizing and optimization
- Know the image formats well enough to pick ones like SVG where they fit, and know your audience well enough to default to the most modern format you can get away with.
- Use
srcsetandsizesto send appropriately sized files and save bandwidth across devices. Creating those variants is image-dependent — pre-determined sizes won't get you the most efficiency. - Optimize the original and every variant. Different optimization tools produce different results, so test several and keep the best — and check that an "optimized" file isn't actually larger or lower quality than the original, which does happen.
Loading behavior and monitoring
- Lazy load so users don't fetch images they never see.
loading="lazy"is native, but the payoff is big enough that polyfilling is often worth it. - The largest image on the page is a candidate for
<link rel="preload" as="image">, which gives the best possible LCP. decoding="async"has a place, though knowing exactly when to use it is its own puzzle.- Provide fallback styling for failed loads, and consider nicer before-load and fail states such as small blurred previews.
- Run performance monitoring to catch oversized images that break your budgets and to watch for broken-image errors.
Delivery infrastructure
Serve images from a fast, cookie-less, global CDN. Add <link rel="preconnect"> and <link rel="dns-prefetch> to the CDN domain(s) — spelled correctly, that's <link rel="dns-prefetch"> — and wire this up only for staging and production, never in dev. Your own servers should remain the canonical source of the images so a CDN can be swapped out when needed.
Automation and pragmatic trade-offs
Getting all of this done together while staying practical with your time is, honestly, close to impossible. Tooling helps: Eleventy Image and gatsby-plugin-image are both well regarded for automating as many of these best practices as they can. Addy Osmani covers the territory in more depth in his Smashing Magazine article and in a full book.
The other option is doing a subset — the biggest wins — and accepting the trade-off. Jake Archibald's technique, described in "Half the size of images by optimising for high density displays":
Here’s the technique I use for most images on this blog: I take the maximum size the image can be displayed in CSS pixels, and I multiply that by two, and I encode it at a lower quality, as it’ll always be displayed at a 2x density or greater. Yep. That’s it.
That echoes Dave Rupert's 1.5× hack from 2013.



