Lazy images without dimensions can stay 0×0 and never enter the viewport. Always set width/height (or CSS aspect-ratio).
srcset
Mixing w and x
One srcset must use either width descriptors or density descriptors — not both.
legacy
Presentational attributes
Replace align, border, hspace, and vspace with CSS.
css
Background vs img
CSS backgrounds are for decoration. Meaningful pictures belong in <img> so alt and semantics stay available.
Compatibility
Browser Support
The <img> element is core HTML embedded content in every browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<img>
Supported everywhere for decades. Chrome, Firefox, Safari, Edge, and Opera all support it. Attributes such as loading and decoding are progressive enhancements.
99%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerAll
Supported
<img>Widely supported
Bottom line: Safe to use everywhere. Prefer modern attributes (srcset, loading) as enhancements, not requirements for basic embeds.
Remember
Key Takeaways
Role:<img> embeds a picture — void element with src/srcset and alt.
Must-haves: useful alt, size hints, and a real image URL.
Responsive:srcset/sizes or <picture> when one file is not enough.
Practice: lazy-load off-screen images; never replace content images with CSS backgrounds alone.
One line: embed with <img src alt>, size it, and enhance with srcset or loading when needed.
UA style
Default CSS Settings
User agents treat <img> as a replaced element. Exact rules vary; a common idea:
Without HTML size attributes, many engines fall back toward a 300×150 placeholder box until the intrinsic size is known. Prefer explicit width / height.
Frequently Asked Questions
The img element embeds an image into the document. It is a void element: you set src (or srcset) and usually alt, with no closing tag.
Yes in practice. Provide meaningful alternative text for content images. Use alt="" only for pure decoration so assistive technology can skip it.
Always use img. There is no standard HTML image tag for page pictures. See the image tag tutorial for that common mistake.
They let the browser reserve space and compute aspect ratio before the file loads, which reduces layout shift. You can still scale with CSS.
Use picture when you need art direction or different formats (for example WebP with a JPEG fallback). picture still requires an img inside as the final choice.
No. Use loading="lazy" for below-the-fold images. Keep important above-the-fold or LCP images eager so they load immediately.