Web design and digital-business ideas grounded in real tasks.

CSS image-set chooses between image candidates for a background

A web designer comparing crisp and soft versions of the same background image on screens.
AI-generated photographic illustration; not documentary photography.

A decorative background may look sharp on one screen and soft on another. CSS image-set() lets a declaration offer alternative image resources with resolution information, so the browser can choose among them.

MDN’s image-set reference explains the candidate syntax and selection considerations. Offering a 2x resource does not mean every browser must download it in every situation. Device characteristics and user-agent decisions remain part of the choice.

A small example with a fallback

.welcome-panel {
  background-image:
    url("leaves-small.webp");
  background-image: image-set(
    url("leaves-small.webp") 1x,
    url("leaves-large.webp") 2x
  );
}

The first declaration supplies an ordinary background image. The second offers two versions where supported. These filenames are illustrative; the larger file should actually contain the additional resolution described by its label. Renaming an identical low-resolution file does not add detail.

Prepare both versions from the same composition so that choosing another resource does not unexpectedly change the subject. Then inspect the background at the dimensions the design will use. A large source can still look poorly composed when the CSS crops it aggressively.

Check the request, not only the screenshot

Use a test page and the browser’s network panel to see which resource was requested. Repeat under the device conditions relevant to the site, taking account of caching. Record the viewport, pixel density and observed file rather than assuming the candidate name proves what loaded.

Also consider what happens if the image does not appear. A decorative pattern should not carry the only readable version of a heading or instruction. If the picture conveys essential content, use appropriate HTML image markup and a meaningful text alternative instead of relying solely on a CSS background.

The useful result is a deliberate choice of resources that preserves the design’s meaning. More candidate files are not automatically better; each should have a clear role and a size justified by the rendered background.