Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. HTML Tag Dictionary
  3. <img>

<img>

The img element embeds an image into an HTML page. It is a void element with no closing tag. Use the src attribute to specify the image URL and the alt attribute to provide alternative text.

Syntax

<!-- Basic image embed -->
<img src="photo.jpg" alt="Mountain landscape photo">

<!-- Explicit dimensions (recommended to prevent layout shifts) -->
<img src="logo.png" alt="Site logo" width="200" height="80">

<!-- Lazy loading (for images below the fold) -->
<img src="banner.jpg" alt="Banner" loading="lazy">

Attributes

AttributeDescription
srcSpecifies the URL (path) of the image file to display. This attribute is required.
altSpecifies alternative text for the image. Used when the image cannot be displayed or when a screen reader reads the content aloud.
widthSpecifies the display width of the image in pixels.
heightSpecifies the display height of the image in pixels.
loadingControls when the image is loaded. Accepts lazy (deferred loading) or eager (immediate loading).
decodingSpecifies how the image is decoded. Setting async decodes the image asynchronously without blocking other content.

Sample Code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>img element</title>
  <style>
    img { max-width: 100%; height: auto; }
  </style>
</head>
<body>

  <!-- Basic image with explicit width and height to prevent layout shifts -->
  <p>
    <img src="https://placehold.jp/400x200.png"
      alt="Sample image 400x200"
      width="400" height="200">
  </p>

  <!-- Decorative images should have an empty alt attribute -->
  <p>
    <img src="decoration.png" alt="" width="32" height="32">
    What's New
  </p>

  <!-- Images below the fold should use lazy loading -->
  <p>
    <img src="footer-banner.jpg"
      alt="Contact banner"
      width="800" height="100"
      loading="lazy"
      decoding="async">
  </p>

</body>
</html>

Output

A 400x200 placeholder image is displayed. A small decorative icon and the text "What's New" appear side by side, and the footer banner is loaded lazily when it scrolls into view.

Rendered HTML (diagram)
400 x 200 What's New ← Small icon beside text Footer banner (loaded on scroll)

Notes

The alt attribute is important for both accessibility and SEO. Write a concise description of what the image conveys so users relying on screen readers understand the content. On the other hand, decorative images that carry no meaning (dividers, background patterns, etc.) should use alt="" (an empty string). Omitting the attribute entirely causes screen readers to read out the filename instead.

It is strongly recommended to specify width and height attributes. By knowing the image dimensions in advance, the browser can reserve space during page layout, preventing the "layout shift (CLS)" that occurs after the image loads and improving your Core Web Vitals score.

Set loading="eager" (the default) for important above-the-fold images and loading="lazy" for images that require scrolling to see. This improves initial page load speed. The standard CSS approach for responsive images is to apply max-width: 100%; height: auto;.

Browser Compatibility

Chrome Chrome
49 or earlier ×
Firefox Firefox
57 or earlier ×
Safari Safari
18+
5 or earlier ×
Edge Edge
80+
14 or earlier ×
IE IE
11 or earlier ×
Opera Opera
48 or earlier ×
iOS Safari iOS Safari
18+
4 or earlier ×
Android Browser Android Browser
37 or earlier ×
Chrome Android Chrome Android
36 or earlier ×
Firefox Android Firefox Android
79 or earlier ×

If you find any errors or copyright issues, please .