0Pricing
HTML Academy · Lesson

The img Element src alt width height

Embed images correctly with all required attributes.

The img Element

The <img> element embeds an image in the page:

<img src="photo.jpg" alt="A golden retriever playing fetch">
<!-- img is a void element — no closing tag needed -->
<!-- src: path to the image file -->
<!-- alt: text description for screen readers and broken images -->

The src Attribute

The src attribute specifies the image source:

<!-- Relative path -->
<img src="images/logo.png" alt="Company logo">

<!-- Root-relative path -->
<img src="/assets/banner.jpg" alt="Sale banner">

<!-- Absolute URL (external) -->
<img src="https://cdn.example.com/photo.jpg" alt="Mountain view">

<!-- Data URI (inline) -->
<img src="data:image/png;base64,iVBOR..." alt="Icon">

All lessons in this course

  1. The img Element src alt width height
  2. Responsive Images with srcset and sizes
  3. The picture Element for Art Direction
  4. figure and figcaption
← Back to HTML Academy