CKTIS / CSS
image-set(): alternatives for one image
Offer image candidates with resolution and optional type information so the browser can select a usable source.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
background-image: image-set(url("small.png") 1x, url("large.png") 2x);image-set() describes alternatives for one image; it does not stack several background layers. Each candidate can specify a resolution, such as 1x or 2x, and a type() MIME hint. The browser chooses an appropriate candidate using supported formats, display characteristics and its own selection policy, so a particular device-pixel ratio is not an unconditional selection guarantee.
A type() value lets the browser discard a format it does not support before loading it. It does not convert the file, force a decoder or guarantee that the bytes match the label. Use a normal background-image declaration before image-set() when a fallback for browsers without this syntax is required. Nested image-set() functions are not allowed.
The example uses two generated gradient images. It deliberately labels the red candidate with an unsupported MIME type and the blue candidate as image/png, both at 1x; that label does not turn the gradient into a PNG file. The sampled blue pixel proves that the unsupported candidate was filtered out. No network download is involved, and the test does not claim to measure high-density candidate selection.
Examples
const sample=async style=>{const svg='<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><rect width="8" height="8" fill="white"/><foreignObject width="8" height="8"><div xmlns="http://www.w3.org/1999/xhtml" style="width:8px;height:8px;'+style.replaceAll('&','&').replaceAll('"','"')+'"></div></foreignObject></svg>';const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=canvas.height=8;const context=canvas.getContext('2d');context.drawImage(image,0,0);return [...context.getImageData(4,4,1,1).data].slice(0,3).join(',')};
const filtered="image-set(linear-gradient(red,red) 1x type('image/x-cktis-unsupported'), linear-gradient(blue,blue) 1x type('image/png'))";
const supported=CSS.supports('background-image',filtered);
const pixel=await sample('background-image:'+filtered);
const nested=CSS.supports('background-image','image-set(image-set(url(test.png) 1x) 1x)');
console.log('supported='+supported+'; filtered-pixel='+pixel+'; nested='+nested);Result
supported=true; filtered-pixel=0,0,255; nested=false
Both candidates have the same resolution; the result isolates MIME filtering rather than guessing which density the browser will prefer.