HTML <img> srcset Attribute

❮ HTML <img> tag

Example

<img srcset="book.png 320w, cup.png 640w, desk.jpg 1200w" sizes="100vw" src="img-boy.jpg" alt="Boy" width="300" height="200">

Meaning

The srcset attribute specifies one or more strings separated by commas, indicating possible image sources for the user agent to use.

If no descriptor is specified, the source is assigned the default descriptor of 1x.


Standard Syntax

HTML: <img src="URL" alt="text" srcset="URL-list">,
XHTML: <img src="URL" alt="text" srcset="URL-list"/>



Browser Support




Status







Attribute Values

Value Description
URL Source url to an image
Optionally

whitespace followed by one of:

  • A width descriptor (a positive integer directly followed by w). The width descriptor is divided by the source size given in the sizes attribute to calculate the effective pixel density.
  • A pixel density descriptor (a positive floating point number directly followed by x).
❮ HTML <img> tag