: The IMG Element

Last updated: 2026-09-12

<img>The IMG Element

The <img> element embeds an image in the page. It's a void element (no closing tag). The src and alt attributes are required: src specifies the image URL, alt provides alternative text (important for accessibility and SEO).

CategoryLinks & Media
Content ModelNone (void element)
Allowed ParentsAny element that accepts phrasing content
Content TagSelf-closing — no closing tag needed
StatusStandard

📝 Syntax

<img src="image-url" alt="alternative text" width="width" height="height">

⚙️ Attributes

This element supports the global attributes plus the following:

AttributeValueDescription
srcURLThe URL of the image file, either relative or absolute.
altTextAlternative text shown when the image can't load; also read by screen readers.
widthPixelsThe display width of the image in pixels.
heightPixelsThe display height of the image in pixels.
loadingKeywordThe loading strategy for the image.
  • lazy — Defer loading until the image is near the viewport.
  • eager — Load immediately (default).
srcsetURL listA list of candidate images for different screen sizes (responsive images).
sizesMedia condition listDescribes the display width of the image at different viewports.

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
<img> v1 v12 v1 v1 v1
Supported in all major browsers
Warning: Don't omit the alt attribute — critical for screen readers and SEO. Use alt="" for purely decorative images.

❓ FAQ

QIs the alt attribute required for ?
AYes, the alt attribute is required for accessibility. Use alt="" (empty) for purely decorative images, and a descriptive text for informative images. Screen readers rely on alt to describe images to blind users.
QWhat's the difference between and ?
A<img> loads a single image. <picture> contains multiple <source> elements to serve different images based on viewport, resolution, or format support (like WebP vs JPEG).
QShould I use width and height attributes on ?
AYes, always include width and height attributes (matching the image's intrinsic dimensions). This prevents Cumulative Layout Shift (CLS) and improves Core Web Vitals scores.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏