Skip to content
techsnow

HTML Basic Tags

Image Tag

The <img> tag displays an image. It is an empty tag, so it has no closing tag.

Syntax:

<img src="cat.jpg" alt="A grey cat sleeping on a sofa">
AttributeRequired?Purpose
srcYesThe path or URL of the image file.
altYesText describing the image, read by screen readers and shown if the image fails to load.
width / heightRecommendedThe size in pixels. Setting them stops the page jumping while images load.
loadingOptionalloading="lazy" loads the image only when the user scrolls near it.
titleOptionalTooltip on hover.

Image paths

<!-- same folder as the HTML file -->
<img src="logo.png" alt="TechSnow logo">

<!-- inside an images folder -->
<img src="images/team.jpg" alt="Our team">

<!-- from another website -->
<img src="https://example.com/photo.jpg" alt="Photo">

Image formats

FormatBest for
JPGPhotos
PNGGraphics with transparency, screenshots
WebP / AVIFModern, much smaller files for both photos and graphics
SVGLogos and icons; stays sharp at any size
GIFSimple animations
<a href="https://techsnow.com">
  <img src="logo.png" alt="Go to TechSnow home page" width="120" height="40">
</a>