Embed an image in HTML
The tag img well filled, for a page, blog or CMS.
PRACTICAL GUIDE
In a web page, blog or CMS in HTML mode, a hosted image integrates with the tag <img> and its direct link. Two or three additional attributes, and it becomes accessible without blowing up the layout.
Minimum tag
<img src="https://exemple.fr/image.png" alt="Image description">
src receives the direct link the file. alt describes the image for screen readers and displays if it does not load. For a purely decorative image, leave it empty (alt="") rather than omit it.
Indicate the dimensions
<img src="https://exemple.fr/image.png" alt="Description" width="800" height="450">
With width and height, the browser reserves the place before loading, and the text no longer moves when the image arrives. Specify the actual dimensions of the file, then adjust the view in CSS, for example style="max-width:100%;height:auto" so that it doesn't overflow on mobile.
Later load remote images
Add loading="lazy" images located away from the top of the page: the browser only downloads them when approaching scrolling. Do not use it on the main image visible from the opening.
Clickable image
<a href="https://exemple.fr/page"><img src="https://exemple.fr/image.png" alt="Open page"></a>
In this case, the alternative text describes the destination of the link.
Weight and format
A 4,000 pixels photo displayed on 800 slows down the page for nothing: prepare a copy at the display size. At equal quality, the WebP often weighs less; for net text or transparency, keep the PNG. Images Portal accepts PNG, JPG and WebP up to 10 MB without an account.
Also read: insert an image in Markdown. Import Image →