Advertisement
Home Open Editor ❯

HTML srcset Attribute

Example

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

Try this code ❯

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

<element srcset="URL-list">


Applies to:

The srcset attribute can be used on the following element:

Element Attribute
<img> srcset

Advertisement

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).
Home Open Editor ❯
Advertisement