Skip to content

HTML Tutorial Images

HTML Image Attributes: alt, width, height and loading

Lesson 23 of 81 2 min read By Deepak Paswan Updated Oct 4, 2026

A few attributes make images more accessible and faster.

alt text

alt describes the image for people who cannot see it and for when it fails to load. Describe what the image shows in the context of the page.

index.html
HTML
<img src="cat.jpg" alt="A grey cat asleep on a stack of books">

Write what you would say if you described the picture over the phone. Keep it short. Do not start with “image of” or “picture of”.

If an image is purely decoration, use an empty alt. Screen readers will skip it.

index.html
HTML
<img src="divider.png" alt="">

width and height

Setting the real size lets the browser reserve space before the image loads, so the page does not jump.

index.html
HTML
<img src="https://placehold.co/400x200" alt="A grey placeholder" width="400" height="200">

Use CSS such as max-width: 100%; height: auto; so the image still shrinks on small screens.

loading

loading="lazy" tells the browser to wait to download an image until the visitor scrolls near it. Use it for images further down the page, not the main image at the top.

index.html
HTML
<img src="gallery-1.jpg" alt="Shelves of poetry books" width="600" height="400" loading="lazy">
warning
Leaving alt out
A missing alt makes screen readers read the file name aloud. Always include the attribute. Use alt="" when there is nothing to say.

Exercise: describe and size an image

Write an img for team.jpg showing three booksellers at a counter. It is 800 by 450 pixels and below the fold.

Show a possible solution
index.html
HTML
<img src="team.jpg" alt="Three booksellers smiling behind the shop counter" width="800" height="450" loading="lazy">