Loading

The <img> tag is used to embed images into an HTML document. It is a self-closing tag, which means it does not need a closing </img> tag.


Key Attributes of <img>

AttributeDescription
srcSpecifies the source (path or URL) of the image.
altDescribes the image if it cannot be displayed or for screen readers.


Syntax:

<img src="image-path" alt="description">


Example:

<!DOCTYPE html>
<html>

<head>
    <title>Image Tag</title>
</head>

<body>
    <h1>Image Tag Example</h1>
    <img src="cat.jpg" alt="cat" />
</body>

</html>

Output:

Uploaded Image

The page will display a heading and an image named cat.jpg. If the image is missing, the word 'Cat' will be shown in its place.

Key Point

  • Always provide the alt attribute it improves accessibility and SEO.
  • You can also add optional attributes like width, height or style for better control.