<img>

The <img> element displays an image on the web page.

Syntax

<img src="image URL" alt="text used for accessibility" />

The <img> element has no closing tag and it cannot have other tags inside of it. It uses attributes to set properties, some of which include:

  • src sets the URL or filename of images that support many formats (GIF, JPEG, PNG, etc.).`
  • alt is an alternative text used by screen readers and when the image does not load.
  • height is the height of the image, measured in pixels.
  • width is the width of the image, measured in pixels.

Example

Below is an example of an image wrapped in an <a> element which creates an image link:

<html>
<head> </head>
<body>
<a href="https://codecademy.com">
<img
src="cc_logo.png"
alt="Codecademy Home Page"
width="256"
height="64"
/>
</a>
</body>
</html>

This is what the rendered image look like:

Codecademy logo

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn HTML on Codecademy