Originally published in January 2021 as a three-part series. Updated November 2026 into one guide, with current image formats, Amplience Smart Images and client hints.
To optimize images for the web, serve each visitor an image sized for their screen, in the most efficient format their browser supports, and cropped for their layout. HTML gives you srcset, sizes and the picture tag to do this. An image API like Amplience Dynamic Media generates every variant from one master image.
Key takeaways
Serve images sized for each screen with srcset and sizes, so phones don’t download desktop-sized files.
Use modern formats such as AVIF and WebP, with JPEG as a fallback. Amplience Smart Images picks the best one automatically with fmt=auto.
Use the picture tag for art direction, when a different crop suits a different layout.
Point of interest metadata and URL templates in Amplience Dynamic Media let one master image produce every crop and size.
Client hints can tailor size and quality to the device and connection, but only Chromium-based browsers support them, so treat them as an enhancement.
Why does image optimization matter?
Images are usually the heaviest part of a web page, and page speed is tightly linked to how big those files are. Slower pages lose engagement and conversions. Images also affect Core Web Vitals, because the largest element on screen when a page loads is very often an image.
Getting it right isn’t simple. Smartphones brought portrait and landscape screens of every size, high-density displays need more pixels, new image formats keep arriving, and connection speeds range from patchy 3G to fast 5G.
HTML has well-supported features that handle most of this, and an image API removes most of the manual work. Amplience Dynamic Media, part of Amplience DAM, creates every size, format and crop you need from a single master image.
How do you serve the right image size with srcset?
A standard image tag works in every browser:
1<img src="cat.jpg" alt="A tabby cat asleep on a sofa">
The problem is choosing one file for every screen. Too small, and it looks blurry stretched across a large high-density display. Too large, and a mobile user on a slow connection may give up before it loads.
A 275KB image (1,280 x 854 pixels), for example, can take almost 7.5 seconds to load on a slow mobile connection.
Pixel density descriptors
The srcset attribute lets you offer several versions and let the browser choose, based on what it knows about the device. Pixel density descriptors (1x, 2x, 3x) suit images shown at a fixed width:
1<img 2 src="cat.jpg?w=300" 3 srcset="cat.jpg?w=300 1x, 4 cat.jpg?w=600 2x, 5 cat.jpg?w=900 3x" 6 width="300" height="200" 7 alt="A tabby cat asleep on a sofa">
You don’t need to create each version by hand. With an image API, you upload one high-quality master and request each size with a URL parameter. In the Amplience Media Delivery API, w sets the width.
Width descriptors and the sizes attribute
Fixed widths are rare in responsive layouts. When an image scales with the page, width descriptors tell the browser how wide each version is, and the sizes attribute tells it how much space the image will take up:
1<img 2 src="cat.jpg?w=600" 3 srcset="cat.jpg?w=300 300w, 4 cat.jpg?w=600 600w, 5 cat.jpg?w=900 900w, 6 cat.jpg?w=1680 1680w" 7 sizes="(min-width: 1681px) 1680px, 100vw" 8 width="1680" height="1120" 9 alt="A tabby cat asleep on a sofa">
Here, the sizes attribute says: on screens 1,681px wide or more, the image is 1,680px wide. Otherwise, it fills the viewport.
The browser combines this with the device pixel ratio. On a 375px-wide phone with a pixel ratio of 2, it needs an image 750px wide. 600w is too small, so it picks 900w and scales it down slightly.
A little analysis of your traffic shows which screen sizes your visitors use, so you can build a sensible list of widths. With Amplience, adding a width to that list is a URL change, not a new file.
Two more attributes are worth adding to every image. Width and height let the browser reserve space before the image loads, which stops the page jumping around.
1loading="lazy"
delays images below the fold, while your main hero image should load straight away.
How do you serve modern image formats?
Getting the size right is only half the job. Format matters too. JPEG, PNG and GIF work everywhere. WebP and AVIF produce much smaller files at the same quality, and modern browsers support both. Older formats such as JPEG 2000 and JPEG XR have largely given way to them.
The picture tag lets you offer several formats. The browser works down the list and uses the first one it supports, and the <img> inside is the fallback:
1<picture> 2 <source type="image/avif" srcset="cat.jpg?fmt=avif"> 3 <source type="image/webp" srcset="cat.jpg?fmt=webp"> 4 <img src="cat.jpg" alt="A tabby cat asleep on a sofa"> 5</picture>
How do you use the picture tag for art direction?
Scaling an image isn’t always enough. A wide landscape shot shrunk onto a portrait phone screen can lose the thing that matters, whether that’s the product, the model or the detail. Designers solve this with a different crop for each layout, and the picture tag delivers it with media conditions:
1<picture> 2 <source media="(min-width: 1024px)" srcset="cat-landscape.jpg"> 3 <source media="(min-width: 760px)" srcset="cat-portrait.jpg"> 4 <img src="cat-small-portrait.jpg" alt="A tabby cat asleep on a sofa"> 5</picture>
The trouble starts when you combine everything. Three crops, each in three formats, each with its own srcset of widths, means nine source elements and dozens of URLs for one image. It’s hard to read and easy to break, and it means preparing a separate file for every crop.
How does Amplience simplify responsive images?
Amplience Dynamic Media removes most of that complexity. Here’s how.
Point of interest
Instead of cropping separate files, you mark the important part of the image once. In Amplience, you set a point of interest in the user interface, and it’s saved as metadata with x, y, width and height values.
Dynamic Media then creates any crop around that point, straight from the URL:
1https://cdn.media.amplience.net/i/youraccount/husky?w=300&poi=0.167,0.125,0.245,0.236&scaleFit=poi&sm=aspect&aspect=2:3
Change the aspect value and you get portrait, landscape or square from the same master, with the subject kept in frame.
URL templates
Typing those values into every URL would be tedious, so Amplience lets you save them as templates. A $poi$ template can read the point of interest straight from the image’s metadata:
1&scaleFit=poi&poi={$this.metadata.pointOfInterest.x},{$this.metadata.pointOfInterest.y},{$this.metadata.pointOfInterest.w},{$this.metadata.pointOfInterest.h}
You can do the same for common shapes. For example, a $landscape$ template could hold &sm=aspect&aspect=16:9. A URL then only needs the width:
1https://cdn.media.amplience.net/i/youraccount/cats?$poi$$landscape$&w=2048
Automatic face detection
You can skip the manual step entirely. Amplience image recognition detects faces as images are uploaded and stores their position as metadata. A template can use that position as the point of interest:
1poi={$this.metadata.detectedFaces.data.boundingBox.left},{$this.metadata.detectedFaces.data.boundingBox.top},{$this.metadata.detectedFaces.data.boundingBox.width},{$this.metadata.detectedFaces.data.boundingBox.height}
Saved as a $facePoi$ template, every crop keeps the face in frame, whatever the size or shape.
Amplience Smart Images
Amplience Smart Images removes the need to list formats yourself. Add fmt=auto to the URL and Dynamic Media returns the most efficient format the browser supports: AVIF, WebP, JPEG 2000, JPEG or PNG. AVIF needs Accelerated Media on your account. Add qlt=default to apply tuned quality settings for whichever format is chosen. Note that fmt=auto has to be in the URL itself, not in a template.
Put it all together and the nine-source picture tag becomes three sources, one per crop, with no extra files and no format list:
1<picture> 2 <source 3 media="(min-width: 1024px)" 4 srcset="https://cdn.media.amplience.net/i/youraccount/cats?$poi$$landscape$&w=1024&fmt=auto&qlt=default 1024w, 5 https://cdn.media.amplience.net/i/youraccount/cats?$poi$$landscape$&w=1440&fmt=auto&qlt=default 1440w, 6 https://cdn.media.amplience.net/i/youraccount/cats?$poi$$landscape$&w=2048&fmt=auto&qlt=default 2048w" 7 sizes="100vw"> 8 <source 9 media="(min-width: 760px)" 10 srcset="https://cdn.media.amplience.net/i/youraccount/cats?$poi$$portrait$&w=768&fmt=auto&qlt=default 768w, 11 https://cdn.media.amplience.net/i/youraccount/cats?$poi$$portrait$&w=1536&fmt=auto&qlt=default 1536w" 12 sizes="100vw"> 13 <img 14 src="https://cdn.media.amplience.net/i/youraccount/cats?$poi$$square$&w=412&fmt=auto&qlt=default" 15 srcset="https://cdn.media.amplience.net/i/youraccount/cats?$poi$$square$&w=320&fmt=auto&qlt=default 320w, 16 https://cdn.media.amplience.net/i/youraccount/cats?$poi$$square$&w=412&fmt=auto&qlt=default 412w, 17 https://cdn.media.amplience.net/i/youraccount/cats?$poi$$square$&w=824&fmt=auto&qlt=default 824w" 18 sizes="100vw" 19 alt="Two cats sitting on a windowsill"> 20</picture>
If you don’t need different crops for different layouts, you don’t need the picture tag at all. A single <img> with srcset, sizes and fmt=auto covers size and format.
What are client hints, and how do they help?
Client hints go a step further. They’re HTTP request headers that the browser sends to the server, describing the device and connection, so the server can choose the right image instead of listing every option in your HTML.
How client hints work
Your server opts in by sending an Accept-CH response header listing the hints it wants:
1Accept-CH: Sec-CH-DPR, Sec-CH-Width, Sec-CH-Viewport-Width, RTT, ECT, Downlink
Browsers that support client hints then include those values in later requests. The hints that matter most for images are:
Width: the space available for the image, calculated from its sizes attribute, with the device pixel ratio already factored in.
DPR: the device pixel ratio.
RTT, ECT and Downlink: network conditions, meaning round-trip time, effective connection type (slow-2g, 2g, 3g or 4g) and estimated bandwidth.
Save-Data: sent when a user has asked their browser to use less data.
With width, the browser tells you exactly how much space it has, so the image never needs stretching or squashing:
1<img src="/images/cats" sizes="(max-width: 576px) 100vw, 50vw" alt="Two cats sitting on a windowsill">
Using client hints with Amplience
Browsers don’t send most hints to a different domain, such as an image CDN, by default. One way around this is to route image requests through your own server, read the hints there, and request the right image from the Amplience Media Delivery API.
The Node.js example below adjusts width and quality based on the device and connection:
1import express from "express"; 2 3const app = express(); 4const IMAGE_BASE = "https://cdn.media.amplience.net/i/youraccount/"; 5 6// Ask the browser to send client hints 7app.use((req, res, next) => { 8 res.set("Accept-CH", "Sec-CH-DPR, Sec-CH-Width, Sec-CH-Viewport-Width, RTT, ECT, Downlink"); 9 next(); 10}); 11 12app.get("/images/:name", async (req, res) => { 13 // Use sensible defaults, as hints aren't always sent 14 const width = Number(req.get("Sec-CH-Width")) || 800; 15 const dpr = Number(req.get("Sec-CH-DPR")) || 1; 16 const downlink = Number(req.get("Downlink")) || 10; 17 const saveData = req.get("Save-Data") === "on"; 18 19 // When Save-Data is on, skip the 2x and 3x versions 20 const finalWidth = saveData ? Math.round(width / dpr) : width; 21 22 // Lower the quality on slower connections 23 const quality = 24 downlink < 1 ? 40 : 25 downlink < 3 ? 50 : 26 downlink < 5 ? 60 : 27 downlink < 8 ? 70 : 28 downlink < 10 ? 80 : 90; 29 30 const url = `${IMAGE_BASE}${encodeURIComponent(req.params.name)}?w=${finalWidth}&qlt=${quality}`; 31 const image = await fetch(url); 32 33 res.set("Content-Type", image.headers.get("content-type")); 34 res.set("Vary", "Sec-CH-Width, Sec-CH-DPR, Downlink, Save-Data"); 35 res.send(Buffer.from(await image.arrayBuffer())); 36}); 37 38app.listen(3000);
The Vary header matters. It tells caches that the response changes with these hints, so a small low-quality image meant for one visitor isn’t served to everyone.
Network hints are especially useful when connections get crowded. If you’re a retailer advertising at a concert or a sports event, thousands of people on the same mobile mast can make a fast connection feel like 3G. Serving lighter images in that moment can be the difference between a sale and a bounce.
In a simple test on a device with a high pixel ratio, the same pair of images came in at 901KB and 311KB with no throttling, 349KB and 96.7KB on a throttled fast 3G connection, and 38.3KB and 14.2KB on fast 3G with Save-Data on.
Browser support
Client hints are supported in Chromium-based browsers, such as Chrome and Edge, but not in Safari or Firefox. Use them as an enhancement on top of srcset and sizes, not a replacement. Browsers that don’t send hints simply get your defaults.
Which techniques should you use?
Every image: srcset and sizes for the right size, width and height to prevent layout shift, and lazy loading below the fold.
Formats: fmt=auto with Amplience Smart Images, so you never have to maintain a list of formats.
Different crops for different layouts: the picture tag, with point of interest and URL templates so one master image produces every crop.
Extra performance for Chromium visitors: client hints, to tailor size and quality to the device and connection.
Amplience Dynamic Media handles the heavy lifting: one master image, every size, format and crop on demand, delivered through a global CDN. Explore Amplience Dynamic Media to see how it fits your stack.