Images

The <img> element embeds an image in a page. It's a void element — it points to an image file rather than wrapping content.

Basic image

Try it yourself
Result

The two required-in-practice attributes

  • src — the path or URL to the image file. Without this, there's nothing to display.
  • alt — a text description of the image. It displays if the image fails to load, and it's read aloud by screen readers, so it should describe what's actually in the image.

Setting a size

You can control the display size with width and height attributes, given in pixels. Try changing the numbers below:

Try it yourself
Result
Note: setting width and height helps the browser reserve space for the image before it loads, which prevents the page from jumping around as images appear.