They provide responsiveness to images, allowing them to scale depending on the device size or screen resolution and load in the optimal size, saving traffic and increasing performance. Let’s look at one code example: picture !– WebP — source type “image/webp” srcset “image-300w.webp 300w, image-600w.webp 600w, image-1200w.webp 1200w” sizes”(max-width: 600px) 300px, (max-width: 900px) 600px, 1200px” !– JPEG — img src “image-300w.jpg” srcset “image-300w.jpg 300w, image-600w.jpg 600w, image-1200w.jpg 1200w” sizes “(max-width: 600px) 300px, (max-width: 900px) 600px, 1200px” alt “Описание изображения” /picture.
The srcset attribute is us under img to specify characteristics
Of the images. Each is list with a ‘w’, which specifies the width of the image in pixels. This is requir because browsers are unable to determine the mom database size of an image until it has been load . The sizes attribute is us together with srcset to select a resource. It specifies the image width for different viewing areas. So, for screens up to 600 px, it is advisable to choose an image up to 300 px wide, and for screens up to 900 px wide 600 px.
For larger ones 1200 px
Without them, the browser will use the entire width of the viewport, and we don’t want that. You can also use the ‘x’ descriptor, which forces the unleash your creativity with genie browser to choose the most appropriate image size depending on the device’s screen resolution (e.g. 1x, 2x, or 3x for standard, retina, and super retina screens. You can also use the ‘x’ descriptor for situations where the image size is constant. This is true for retina displays, for example.
An the ‘w’ descriptor is suitable for layouts where
The size changes depending on the viewport. Yes, working with sizes and srcset attributes is quite difficult to automate. Even if you know the powder data page layout well. But fortunately, not long ago, Chrome add support for sizes “auto”, which allows the browser to determine the size of load images by srcset bas on the HTML layout and CSS.