Skip to content

Instantly share code, notes, and snippets.

@GiovanniRiefolo
Last active May 17, 2023 13:32
Show Gist options
  • Save GiovanniRiefolo/b898d73967fff75f80dda745e02bb5dc to your computer and use it in GitHub Desktop.
Save GiovanniRiefolo/b898d73967fff75f80dda745e02bb5dc to your computer and use it in GitHub Desktop.
Responsive image full markup
<!DOCTYPE html>
<html>
<head>
<title>Responsive image full markup example</title>
<!--
Don't preload if <picture> is used
@https://web.dev/preload-responsive-images/#preload-and-lesspicturegreater
-->
<link rel="preload" href="image_landscape.jpg" imgsrcset="image_landscape.jpg 1x, image_landscape@2x.jpg 2x" as="image">
</head>
<body>
<!--
Responsive images full markup example with accessibility features,
optimized for performance. Code refer to a fake image.jpg with
size of 1024*768px for diffrent DPR
-->
<figure>
<picture>
<!--
Pass the different versions for "art direction"
-->
<source srcset="image_portrait.jpg"
media="(max-width: 650px)"
width="650" height="866"
type="image/jpg">
<source src="image_square.jpg"
media="(max-width: 1024px)"
width="1024" height="1024"
type="image/jpg">
<!--
Pass the PGN version
-->
<source srcset="image_portrait.png"
media="(max-width: 650px)"
width="650" height="866"
type="image/png">
<source srcset="image_square.png"
media="(max-width: 720px)"
width="720" height="720"
type="image/png">
<source srcset="image_landscape.png"
media="(min-width: 1025px)"
width="1024" height="1024"
type="image/png">
<!--
Pass the WEBP version
-->
<source srcset="image_portrait.webp"
media="(max-width: 650px)"
width="650" height="866"
type="image/webp">
<source srcset="image_square.webp"
media="(max-width: 720px)"
width="720" height="720"
type="image/webp">
<source srcset="image_landscape.webp"
media="(min-width: 1025px)"
width="1024" height="1024"
type="image/webp">
<!--
Fallback image
fetchpriority is not a standard yet,
avoid prioritizing to much image download
-->
<img src="assets/image_landscape.jpg"
width="1024" height="768
srcset="image_landscape.jpg 1x, image_landscape@2x.jpg 2x"
sizes="100w"
loading="lazy"
decoding="async"
fetchpriority="low"
alt="Short image description"
aria-details="details"/>
<picture>
<figcaption>
<small>Image caption, useful for legends or <pre>&lt;figure&gt;</pre> content</small>
<figcaption>
</figure>
<p id="details">Long description of the image giving exaustive details on the content represented.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment