Example 1 — Image Width and Height
Set both dimensions so the browser can reserve space before the image loads.
<img
src="/images/html.png"
alt="HTML logo"
width="128"
height="128"> How It Works
- Use integers.
height="128"means 128 CSS pixels — do not write128px. - Match width. Setting both
widthandheightlets the browser compute an aspect ratio early. - Add alt text.
altkeeps the image accessible if it fails to load. - Reduce layout shift. Reserved space stops nearby text from jumping when the image arrives.


