HTML - <img> tag in HTML

The <img> tag in HTML is used to display images on a web page. It is an empty tag, meaning it does not have a closing tag.

Here are 6 common attributes of the <img> tag with examples:

  1. src
    Specifies the path to the image file.
    Example:
    <img src="image.jpg">

  2. alt
    Provides alternative text for the image if it cannot be displayed. It also improves accessibility.
    Example:
    <img src="image.jpg" alt="A scenic mountain view">

  3. width
    Specifies the width of the image in pixels or percentage.
    Example:
    <img src="image.jpg" ">

  4. height
    Specifies the height of the image in pixels or percentage.
    Example:
    <img src="image.jpg" height="200">

  5. title
    Gives additional information about the image, shown as a tooltip when the mouse hovers over it.
    Example:
    <img src="image.jpg" title="Mountain View">

  6. loading
    Specifies how the image should be loaded.
    Values: "lazy" (load when needed), "eager" (load immediately)
    Example:
    <img src="image.jpg" loading="lazy">

Complete example:

<img src="nature.jpg" alt="Green forest" " height="300" title="Forest Image" loading="lazy">