← HTML Fundamentals
Links, images and media · 15 MIN

Images and alternative text

Images and alternative text

Use img with src and alt. Alternative text should communicate the purpose of an informative image; decorative images should use an empty alt attribute. Set width and height where possible to reduce layout shifts, and choose suitable image formats and sizes.

Try it yourself

Change the example, run it, and explain the result in your own words. Then create one variation of your own.

Key idea

Use the example as a starting point, not something to memorize. Practise, inspect the result and make small improvements.

Code example

<img src="images/workspace.jpg" alt="A laptop on a desk" width="640" height="420">