CKTIS / HTML
imagesizes — image source size for preloading
The imagesizes attribute describes an image's expected width so the browser can select a resource from imagesrcset during preloading. It applies to link with rel="preload" and as="image"; it does not set the image's layout width.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<link rel="preload" as="image" imagesrcset="…" imagesizes="(max-width: 600px) 100vw, 50vw">imagesizes supplies the source size used when selecting an image from imagesrcset. It is allowed only on a link element with rel="preload" and as="image". When imagesrcset contains width descriptors w, imagesizes is required.
Its value is a source size list, like an image's sizes: (max-width: 600px) 100vw, 50vw means the full viewport width up to 600 CSS pixels, then half that width. The first matching condition applies; the final length is the fallback. Percentages are not allowed as source size lengths.
Match imagesizes to the target image's sizes, and imagesrcset to its srcset, so both stages select a consistent resource. The declaration describes the expected width but does not set it — define layout separately, for example with CSS. Do not confuse it with the link element's sizes, which describes icon dimensions.
The example uses two embedded SVG candidates (80w and 160w), each containing a teal rectangle, so no separate files are needed. Both imagesizes and sizes are fixed at 80px, regardless of viewport width. The console confirms that the values match and reports the 80px source size separately from the 64px layout width set by CSS. The example does not measure whether preloading speeds up downloads.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Source size for image preloading</title>
<link id="preload" rel="preload" as="image" imagesizes="80px"
imagesrcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='80'%20height='40'%3E%3Crect%20width='80'%20height='40'%20fill='teal'/%3E%3C/svg%3E 80w,
data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='160'%20height='80'%3E%3Crect%20width='160'%20height='80'%20fill='teal'/%3E%3C/svg%3E 160w">
<style>
#sample { display: block; width: 64px; height: auto; }
</style>
</head>
<body>
<h1>Preload source size and layout width</h1>
<img id="sample" alt="Teal rectangle" width="80" height="40" sizes="80px"
src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='80'%20height='40'%3E%3Crect%20width='80'%20height='40'%20fill='teal'/%3E%3C/svg%3E"
srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='80'%20height='40'%3E%3Crect%20width='80'%20height='40'%20fill='teal'/%3E%3C/svg%3E 80w,
data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='160'%20height='80'%3E%3Crect%20width='160'%20height='80'%20fill='teal'/%3E%3C/svg%3E 160w">
<script>
const preload = document.getElementById('preload');
const image = document.getElementById('sample');
if ('imageSizes' in preload) {
console.log(`Preload source size: ${preload.imageSizes}`);
console.log(`Preload and image source sizes match: ${preload.imageSizes === image.sizes}`);
console.log(`Image layout width: ${getComputedStyle(image).width}`);
} else {
console.log('imagesizes reflection is unsupported');
}
</script>
</body>
</html>Result
Preload source size: 80px Preload and image source sizes match: true Image layout width: 64px
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.