The <img> tag is used to display images on a webpage.
It is an empty tag (no closing tag required).
| Attribute | Purpose | Example |
|---|---|---|
| src | Specifies image path or URL | src="photo.jpg" |
| alt | Alternative text if image fails | alt="Beautiful sunset" |
| width | Sets image width | width="300" |
| height | Sets image height | height="200" |
| Step | Explanation | Code |
|---|---|---|
| Step 1 | Basic syntax of image tag | <img src="image.jpg" alt="Description"> |
| Step 2 | Add local or online image source | src="photo.jpg"src="https://example.com/photo.jpg" |
| Step 3 | Add alternative text for accessibility | alt="A beautiful sunset" |
| Step 4 | Set width and height (optional) | <img src="photo.jpg" alt="Sample" width="300" height="200"> |
<!DOCTYPE html>
<html>
<head>
<title>Image Example</title>
</head>
<body>
<h2>My Image</h2>
<img src="flower.jpg" alt="Flower Image" width="300">
</body>
</html>
The <img> tag inserts images using the src attribute. The alt, width, and height attributes improve accessibility and display control.