
<img>
Tag in HTML – Full Details with suitable example
- This is used to create image control on webpage.
- The src property of image tag is to a sign. image on image control.
- The
<img>
tag is used to embed images in a webpage. - It is an empty (self-closing) tag, meaning it does not require a closing tag like
<img> ... </img>
.
✅ Syntax
-
src
→ Path or URL of the image file (src=source). -
alt
→ Alternative text (important for SEO and accessibility). -
width
/height
→ Sets image dimensions (in pixels or %).
⚙️ Attributes of <img>
Here are the important attributes:
-
src (source)
-
Defines the path or URL of the image.
-
Example:
-
-
alt (alternative text)
-
Provides text if the image is not loaded.
-
Used by screen readers for visually impaired users.
-
Example:
-
-
width and height
-
Defines the size of the image.
-
Units: pixels (
px
) or percentage (%
). -
Example:
-
-
title
-
Displays tooltip text when hovering over the image.
-
Example:
-
-
loading (HTML5)
-
Controls how images load.
-
Values:
lazy
(loads when in view),eager
(loads immediately). -
Example:
-
-
align (Deprecated)
-
Used in older HTML to align images (
left
,right
,middle
). -
Example:
-
-
border (Deprecated)
-
Adds a border around the image.
-
Example:
-