HTMLbeginner 6 min
Add pictures to a page with the img tag and write alt text that helps everyone.
How to show an image, why alt text matters, and how to control its size.
Pictures make pages friendlier, but they also have to work for people who cannot see them, and for slow connections where they fail to load.
The <img> tag shows an image. It is a void element: no content, no closing tag. Two attributes are essential:
src: where the image file lives (a URL or a file path).alt: a short text description used by screen readers and shown if the image fails to load.You can set width and height in pixels so the browser reserves space before the image loads, which stops the page from jumping around.
If an image is purely decoration, use an empty alt: alt="". Screen readers then skip it.
<img starts the tag. There is no closing tag.src points to the file. Here it is an online placeholder image.alt describes the picture in words.width and height tell the browser the size before download.Change the text in the src address (after text=) and update the alt to match.
alt. Always include it, even if empty for decoration.src shows the alt text instead. That is a good clue to check the path.<img src="..." alt="..."> shows a picture.alt text, or alt="" for decoration.width and height to avoid layout jumps.Next: lists.
<img
src="https://placehold.co/300x160/png?text=Hello"
alt="A grey box with the word Hello"
width="300"
height="160"
>