HTML Tags

HTML <img> Tag

The <img> tag in HTML is used to embed images into a webpage. It is an empty tag (no closing tag) and requires attributes like src (source URL of the image) and alt (alternative text for accessibility and SEO).

It helps add visual content like icons, illustrations, and photographs to enhance web design and user experience.

Syntax

<img src="image.jpg" alt="Description of image">

Attributes

AttributeDescriptionExample
srcSpecifies the path to the image file.src="photo.png"
altProvides alternate text if image fails to load.alt="Profile picture"
widthDefines the image width (in px or %).width="300"
heightDefines the image height (in px or %).height="200"
loadingDefines how the image should load (lazy or eager).loading="lazy"
titleProvides extra info on hover.title="HTML5 Logo"
srcsetDefines multiple image sources for responsive design.srcset="img-400.jpg 400w, img-800.jpg 800w"
sizesSpecifies how different image sizes are used for screen widths.sizes="(max-width: 600px) 480px, 800px"
crossoriginIndicates if image should be fetched with CORS.crossorigin="anonymous"

Example

<h2>Example: Adding an Image</h2>
<img src="https://picsum.photos/seed/picsum/400/300" alt="Beautiful sunrise over the mountains" width="400" height="250">

Output

Browser Output

Please use our TryIt Editor to see the output

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes✅Yes

(Displays an image of sunrise on the webpage — width 400px, height 250px)

Notes

  • The <img> tag does not have a closing tag.
  • Always include the alt attribute — it improves accessibility and SEO.
  • Use loading="lazy" for better performance (defers loading until the image is visible).
  • Use responsive image techniques (srcset, sizes) for adaptive layouts.

Conclusion

The <img> tag is the backbone of visual content in web design. When used correctly with attributes like alt, srcset, and loading, it makes websites both beautiful and efficient — ensuring faster loading, better SEO, and accessibility compliance.

Sign In Form

User your email and password to singn in

Provide your email and we will send you a password reset link.

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend