HTML elements with attributes


The <img> element is used to display an image. Let us try to display an image:

The <img> element has an attribute called src. This attribute is used to specify the source of the image being displayed, which in this case is the image URL. Please note that <img> is a self-closing tag.

Although the general rule is that every HTML element must have an opening and closing tag, there are some exceptions. Some elements are self-closing, i.e. they don’t need a closing tag and can optionally be closed in the opening tag itself. <img />, <br />, <hr />, are some self-closing elements.