Resources

Incorporating Images In Modern Web Apps

Incorporating Images In Modern Web Apps

Serve each image at the size the screen needs, in WebP or AVIF with a fallback, lazy-load whatever sits below the first screen, and write alt text for every image that carries meaning. Everything else about images in a web app is taste. Those four decisions are what slow pages, layout jumps and inaccessible interfaces usually trace back to.

Informative or decorative

Decide this per image before you write a line of markup. An informative image, a chart or a product photo, needs descriptive alt text so screen reader users get the same information. A purely decorative one gets an empty alt attribute so it is skipped.

Which format should you use?

MDN’s advice is to prefer WebP or AVIF for raster images, SVG for icons and diagrams, and keep PNG or JPEG as fallbacks.

FormatUse it forWatch out for
AVIFPhotos and animation where file size mattersNewer support (Chrome 85, Firefox 93, Safari 16.1), no progressive rendering
WebPThe safe modern defaultNot as deep a history in older browsers
JPEGPhotos, as a fallbackNo transparency, and sharp-edged charts come out poorly
PNGTransparency and exact reproductionLarger files
SVGIcons, logos, diagramsRarely suits photographs

The picture element lets the browser pick the first format it understands.

Load only what the screen needs

Google’s Core Web Vitals treat a largest contentful paint of 2.5 seconds or less as good, and on many pages that largest element is an image. So the hero image is where performance work starts.

Page layout showing which images load eagerly above the fold, which are lazy-loaded below it, and where SVG fits

  • Add width and height to every image tag so the browser can reserve space and the layout does not jump. web.dev recommends this for all images.
  • Use srcset and sizes so a phone does not download the desktop file.
  • Lazy-load images outside the first screen with loading=lazy, and never lazy-load the likely LCP image. For that one, web.dev suggests fetchpriority=high instead.
  • Serve files from a CDN so they travel a shorter distance.

Chrome’s lazy-loading thresholds are hardcoded: since July 2020 it starts fetching an image when it is within 1250px of the viewport on a 4G connection, and 2500px on 3G or slower. You cannot change that from the page.

The one mistake that shows up everywhere is a lazy-loaded hero.

YouTube player

Security

  • Block hotlinking, so other sites do not serve your files from your bandwidth.
  • Validate every upload on the server, by content and not by file extension.
  • Keep the image-processing library patched and its policy tight.

That last point is not theory. On November 12, 2026, CERT/CC published VU#580079, describing a flaw pattern in ImageMagick-based applications that process attacker-controlled SVG files.

Gallery or carousel

Galleries with thumbnails let people choose what to enlarge. The rotating carousels that advance on their own are riskier, since Nielsen Norman Group advises showing a new panel only when the user asks for it, and in one of its tests a discount panel was visible just 20% of the time. I’d skip auto-rotation unless there is a strong reason. Is a carousel ever the right call?

Consistency is brand work, not decoration

Hero images, product photos and illustrations should share crops, backgrounds and filters, so the pages feel like one product. Logos and custom iconography do the same job for recognition, and users orient themselves faster in an app that looks the same everywhere.

Designers reviewing mobile app layouts on a desktop monitor and laptop

Generated images can fill gaps. An AI image generator can draft infographics and chart visuals, and an AI product image generator can produce extra angles for a listing. A product shot has to match the product you actually ship, so a person should compare every generated image with the real item. For a soft or low-resolution file, an image upscaler can help, though upscaling cannot add detail that was never there.

Check the numbers

Run Lighthouse or the Core Web Vitals report after each change, because image decisions only prove themselves in the measurements. The guide on what Core Web Vitals mean for ranking and speed explains the targets.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.