Lessons
Courses

<img> tag [ English ]

<img> Tag

The <img> tag is used in HTML to display images on a web page.It’s an empty (self-closing) tag, meaning it has no closing tag.It's an inline element, meaning it will only take width required to show the image.

  • Image path can be:

    • Relative → images/pic.jpg
    • Absolute → https://example.com/pic.jpg

Basic syntax

<img src="image.jpg" alt="Description of image">

Important attributes

  1. src (source)

    • Specifies the path or URL of the image.
    <img src="logo.png">
  2. alt (alternative text)

    • Text shown if the image doesn’t load
    • Helps screen readers (accessibility)
    <img src="logo.png" alt="Company Logo">
  3. width and height

    • Set image size (in pixels or %)
    <img src="photo.jpg" width="300" height="200">
  4. title (optional)

    • Shows tooltip on hover
    <img src="photo.jpg" title="This is a photo">

Example

<img src="flower.jpg" alt="Red Rose" width="250">