Responsive image using the srcset attribute

suggest change

Using srcset with sizes

<img sizes="(min-width: 1200px) 580px,
      (min-width: 640px) 48vw,
      98vw"
    srcset="img/hello-300.jpg 300w,
      img/hello-600.jpg 600w,
      img/hello-900.jpg 900w,
      img/hello-1200.jpg 1200w"
    src="img/hello-900.jpg" alt="hello">

sizes are like media queries, describing how much space the image takes of the viewport.

srcset is just telling the browser what images we have available, and what are their sizes.

src is always mandatory image source. In case of using with srcset, src will serve fallback image in case browser is not supporting srcset.

Using srcset without sizes

<img src="img/hello-300.jpg" alt="hello"
     srcset="img/hello-300.jpg 1x, 
       img/hello-600.jpg 2x,
       img/hello-1200.jpg 3x">

srcset provides list of available images, with device-pixel ratio x descriptor.

src is always mandatory image source. In case of using with srcset, src will serve fallback image in case browser is not supporting srcset.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents