Skip to content

Aspect Ratio for Blurry Placeholders

In certain cases, the blurry placeholder might not have the full image width and height. To ensure that the layout does not change when the full-quality image loads and to maintain a consistent user experience, you can add the aspect-ratio CSS property to the style attribute to your images.

By setting the aspect ratio for your blurry placeholders, you can:

  • Prevent layout shifts as the full-quality image loads.
  • Ensure that the image container maintains its dimensions even before the full-quality image is loaded.


Calculate the aspect ratio using the dimensions of the full-quality image (width / height) and apply it to the <img> tag:

  src="data:image/svg+xml, ..."
  data-srcset="/foo.png 1024w, /foo-2x.png 2048w"
  style="aspect-ratio: 16/9;"

Released under the MIT License.