Image Width and Height Attributes Generator (Prevent Layout Shift)

Reads image dimensions from file headers and writes img tags with width, height and an aspect-ratio rule.

Use the tool

Why this tool exists

Images without width and height make the page jump when they load, which hurts Cumulative Layout Shift. The fix is to give the browser the size up front.

The tool reads PNG, JPEG, GIF, WebP, BMP, AVIF, HEIC and SVG headers directly, so it does not decode pixels. It applies the EXIF rotation to JPEGs the way browsers do, and reduces the ratio for you. You get a ready img tag and the matching CSS aspect-ratio.

How to use it

  1. Choose one or more image files.
  2. Set the URL prefix for src.
  3. Copy the img tag for each file.
  4. Keep max-width: 100% and height: auto in your CSS.

Frequently asked questions

Do width and height stop responsive images?

No. With height: auto the browser uses them only to compute the aspect ratio.

What about SVG?

The tool uses width and height, or the viewBox, and rounds to whole pixels.

Why are some JPEG sizes swapped?

The file has an EXIF rotation of 90 or 270 degrees, which browsers apply when showing the image.

Are the files uploaded?

No.