عربي
News
●E-invoicing: the last date to connect for wave 25 is February 1, 2027●WhatsApp Business: service messages are paid after 1,000 free per month●Salla acquires Paylink to strengthen payment solutions for merchants●Google launches a Gemini agent for businesses first, then consumers●Hostinger's White Friday deals continue until December 14

Choose product image sizes for the width of store cards

Use srcset and sizes with a worked example, then inspect which image the browser selects.

The problem

A grid downloads a 1200-pixel product photo for every card, even when a card is 300 pixels wide. Several large downloads can waste bytes. Provide the same image at multiple resolutions and describe the display slot.

The tool

In HTML, srcset lists files with their actual widths while sizes describes how wide the image will appear. The browser selects a resource using the slot, pixel density and other factors. Match the slot description to CSS.

The steps

  1. Export the same crop at widths of 320, 640 and 960 pixels. Check the actual dimensions before declaring width descriptors.
  2. Use src="bag-640.webp" as a baseline and set srcset="bag-320.webp 320w, bag-640.webp 640w, bag-960.webp 960w".
  3. If the card spans the viewport at narrow widths and is 320 pixels above that, try sizes="(max-width: 359px) 100vw, 320px". Adjust for gutters or a different grid.
  4. Set image width and height with the correct aspect ratio so the browser can reserve space. Use CSS to fit the asset to the card without distortion.
  5. With browser caching disabled for the exercise, compare network requests at narrower widths and different pixel densities. Inspect the image's currentSrc.
  6. Record the bytes transferred for one grid before and after the change. Check the first and lower rows separately if their layout differs.

The real cost

The HTML feature is free. Multiple sizes add an export step or consumption in your image-processing service.

The free alternative

Start with a single optimized card image if you cannot export variants. Check whether it stays sharp on a high-density display before replacing every asset.

Notes

  • We have not tried these steps ourselves yet. They are based on the official docs. Button names may change. If your interface differs, follow the docs.
  • The descriptor 640w must match the actual file width.
  • For a different crop on mobile, investigate the picture element. This example focuses on resolution selection.

Sources

  1. developer.mozilla.org

Did you like this guide?

The weekly newsletter is being prepared. Leave your email and we'll send it when it launches.

We use your email only to send the newsletter. Privacy policy