CSS Portal

HTML <img> Tag

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The <img> tag in HTML is used to embed images into a webpage. It is a void element, meaning it does not have a closing tag, and its primary purpose is to display visual content directly within the HTML document. Unlike background images applied through CSS, images added with <img> become part of the document's content, allowing them to be indexed by search engines and accessible to assistive technologies.

The <img> tag can render a wide variety of image formats, such as JPEG, PNG, GIF, SVG, WebP, and more, depending on browser support. Images are loaded from a source URL, which can be either a local file path or an external web address. The tag is inline by default but can be styled with CSS to behave like a block-level element, have responsive dimensions, borders, shadows, or other visual effects.

One of the most important aspects of the <img> tag is its role in content accessibility. When properly used with descriptive alternative text, it ensures that visually impaired users using screen readers can understand the content and context of images. Additionally, images in <img> tags can be part of semantic content, such as figures in articles, product images in e-commerce sites, or visual aids in tutorials and blogs.

The <img> tag also allows for integration with modern web features such as lazy loading, responsive images using the srcset attribute, and optimization for faster page loading. It remains one of the most fundamental and widely used elements in HTML for enriching webpages with visual content.

Properties

Permitted Parents
Any element that accepts embedded content
Content
None. It is an empty element.
Start/End Tags
Start tag: required, End tag: forbidden

Example

<img alt="Sunset Image" src="images/sunset.jpg" width="300" height="226">

Attributes

name
Assigns a name to an image. This is used when referencing the image with stylesheets or scripts. However, you should use the id attribute instead.
src
Location of the image.
alt
Alternate text. This specifies text to be used in case the browser/user agent can't render the image.

Global Attributes

The <img> tag also supports the Global Attributes in HTML5

Event Attributes

The <img> tag also supports the Event Attributes in HTML5

Browser Support

The following information will show you the current browser support for the HTML <img> tag. Hover over a browser icon to see the version that first introduced support for this HTML tag.

This tag is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 26th December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!