HTML - tag

The <img> tag in HTML is used to embed images in a webpage. It is a self-closing tag, meaning it does not have a closing </img> tag.

Basic Syntax:

<img src="image.jpg" alt="Description of image">

Common Attributes of <img>:

Attribute Description
src (Required) Specifies the path (URL) to the image.
alt Provides alternative text if the image cannot be displayed. Helps with accessibility and SEO.
width Sets the width of the image (in pixels or percentage).
height Sets the height of the image.
title Tooltip text that appears when the mouse hovers over the image.
loading Specifies how the browser should load the image: "lazy" (defers loading until needed) or "eager" (default, loads immediately).
style Inline CSS to style the image (e.g., borders, margins).
class Assigns one or more CSS classes to the image.
id Assigns a unique identifier to the image.
usemap Associates the image with a <map> element for clickable areas.

Example with Attributes:

<img 
  src="cat.jpg" 
  alt="A cute cat" 
  " 
  height="200" 
  title="Click to see more cats" 
  loading="lazy" 
  class="responsive-img" 
  id="main-cat-image">