It is possible to include images in HTML documents by using <img> element.

The browsers support different image formats like:


Image Syntax

The <img> tag is used to put an image in an HTML document.

<img src="images/tus.jpg" alt="dog image">

The src attribute tells the browser where to find the image (URL to the image). It can be absolute, or relative, as the above example demonstrates. It is usually relative. This attribute is mandatory for the <img> element.

The alt attribute is the alternative text describing the image. It provides meaningful information for users who are unable to see the image. Users will see this displayed if the image URL is wrong, the image is not in one of the supported formats, or if the image is not yet downloaded. If alt is omitted. validator will give an error.

Note that, like the <br> tag, because the <img> element does not enclose any content, no closing tag is required.

We can style images using CSS.


Image Attributes

In addition to src, alt attributes, <img> supports: