Lesson 6 of 15

Images

The img Element

Images use the <img> tag — a self-closing tag (no closing </img>):

<img src="photo.jpg" alt="A beautiful photo">

Key attributes:

  • src — the image URL or file path
  • alt — alternative text (shown if image fails to load, required for accessibility)
  • width and height — dimensions in pixels
<img src="https://picsum.photos/300/200" alt="Random photo" width="300" height="200">

Why alt text matters

Screen readers read the alt text aloud for visually impaired users. Search engines use it to understand images. Always include a meaningful alt attribute.

Your Task

Add an image with:

  • A src pointing to any image URL
  • An alt description
  • A width attribute
HTML preview loading...
Loading...
Click "Run" to execute your code.