HTML Course

Lesson 5: Images

The <img> Tag

The <img> tag is used to embed images in a webpage. It is a self-closing tag that requires the src (source) attribute and should include the alt (alternative text) attribute for accessibility.

<img src="images/photo.jpg" alt="A beautiful sunset">
Example placeholder image

Image Attributes

<img src="logo.png" alt="Company Logo" title="Our Logo" width="200" height="100">

Absolute vs Relative Paths

You can link to an image using a full URL (absolute) or a path relative to your current file (relative).

<!-- Absolute path -->
<img src="https://example.com/images/photo.jpg" alt="Example">

<!-- Relative path -->
<img src="images/photo.jpg" alt="Example">

Image Formats

Exercise

Create a webpage with:

  1. An image of yourself or a favorite place (use alt text).
  2. A logo or icon from your school site.
  3. One image from the internet using an absolute URL.
  4. Make sure at least one image uses the title attribute.