Use the srcset attribute on an <img> element with density descriptors (e.g., 1x, 2x, 3x) to provide different image resolutions based on the user's display pixel density. This ensures high-DPI displays (like Retina displays) receive high-resolution images while standard displays receive lower-resolution images, optimizing both performance and visual quality.
Implementation requirements:
- Provide images in multiple resolutions.
- Define the
srcset attribute with a comma-separated list of image URLs and their corresponding density descriptors. - Include a
src attribute as a fallback for browsers that do not support srcset.
<img src="example-image-1x.jpg"
srcset="example-image-1x.jpg 1x, example-image-2x.jpg 2x, example-image-3x.jpg 3x"
alt="An example image">