srcset 属性。

下面是一个同时具有常规 src 属性和 srcset 属性的图像(img)元素。有一个样式表将图像尺寸设置为 400x400 像素。在不支持 srcset 的浏览器上,src 属性的值将用作图像源 [默认图像]。在常规分辨率显示器上,将使用 srcset 的 1x 变体 [1x 图像]。在每 CSS 像素具有 2 个设备像素的显示器上,将使用 srcset 的 2x 变体 [2x 图像]。类似地,还有一张 3x 图像和一张 4x 图像

Example of the srcset attribute. Image contains a coloured striped pattern with some inline text that indicates which of the candidate images were selected.

上述图像的 HTML 代码如下:

<img src="image-src.png" srcset="image-1x.png 1x, image-2x.png 2x,
                                 image-3x.png 3x, image-4x.png 4x">