<img>

Displays an image with HTML.
3 min read
Believemy logo

The <img> tag is used to embed images in a web page. This tag is essential for creating a visually appealing interface and conveying information through graphical content (such as images).

It is a self-contained tag (also called "self-closing" 🇺🇸 – meaning it closes on itself) and requires mandatory attributes like src (image source) and alt (alternative text).

 

Structure and Syntax of the <img /> Tag

The <img> tag is an empty tag (it does not encapsulate other tags). It can be styled using the style attribute or through classes (class) and IDs (id), like most HTML tags.

Syntax

HTML
<img src="[URL]" alt="[DESCRIPTION]">
Good to know

The alt attribute defines the alternative text.

Although optional, this attribute is highly recommended for good search engine optimization (SEO) and to provide textual information for visually impaired users.

 

Usage Example

HTML
<img
    src="https://believemy.com/images/site/brand/believemy-new-logo-full-black.svg"
    alt="Believemy Logo"
    style="width: 300px"
>

In this example, the image located at the URL specified in the src attribute is displayed. An alternative text is provided using the alt attribute, and the image is given a width of 300 pixels using the style attribute.

Try it yourself here:

Warning

It is possible to use this tag in two different forms:

  • <img> for its version valid with HTML5;
  • <img /> for its version valid with HTML5 as well as XHTML.

It is therefore not uncommon to see one or the other of the syntaxes, both being widely used.

 

Attributes

Here are the main attributes for the <img> tag:

AttributeDescriptionPossible Value
srcSpecifies the image path or URL.Relative or absolute path.
altProvides a textual description of the image for screen readers or when the image cannot load.Descriptive text.
widthDefines the image width.Value in pixels or percentage.
heightDefines the image height.Value in pixels or percentage.
titleDisplays a tooltip when hovering over the image.Descriptive text.
loadingControls the loading behavior of the image.lazy, eager, or auto.
srcsetProvides multiple sources for loading images optimized for different resolutions.List of sources with dimensions.
sizesIndicates the display width of the image for browsers.Width in CSS units (e.g., 100vw).
referrerpolicySets the HTTP referrer policy for image requests.no-referrer, origin, strict-origin, etc.
usemapAssociates the image with a map defined by the <map> tag.Map name (e.g., #map-name).
crossoriginDefines the CORS policy for the image.anonymous, use-credentials.

 

Browser Compatibility

The <img> tag is compatible with all modern browsers. However, some advanced attributes, such as loading or referrerpolicy, may not be supported in older versions.

BrowserGeneral CompatibilityNotes
ChromeYesSupports loading=lazy.
FirefoxYesSupports srcset.
SafariYesBeware of behavior with modern image formats (e.g., AVIF).
EdgeYes 
Internet Explorer 11PartiallyNo support for srcset.

Related terms

Discover our hTML and CSS glossary

Browse the terms and definitions most commonly used in HTML and CSS development.

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.