HTML Image Element (<img>):
The HTML <img> (image) element is used to embed images within a web page. Images are crucial for enhancing visual appeal and conveying information. Here's a detailed guide on the HTML image element:
- Basic Syntax:
- The <img> element is a self-closing tag that includes the src attribute specifying the source (URL) of the image.
- Source (src) Attribute:
- The src attribute contains the URL or file path of the image. It can be a relative or absolute path.
- Alternative Text (alt) Attribute:
- The alt attribute provides alternative text for the image. It is displayed if the image cannot be loaded and is crucial for accessibility.
- Width and Height Attributes:
- The width and height attributes can be used to specify the dimensions of the image. This helps browsers allocate space before the image is fully loaded.
- Lazy Loading:
- The loading="lazy" attribute can be added to enable lazy loading, which defers the loading of offscreen images until they are about to be displayed.
<img src="image.jpg" alt="Description of the image">
Output:
<img src="image.jpg" alt="Description" width="300" height="200">
<img src="image.jpg" alt="Description" loading="lazy">
Example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>HTML Image Example</title> </head> <body> <h1>Welcome to My Website</h1> <p>This is an example of using the image element in HTML.</p> <img src="example.jpg" alt="Example Image"> <img src="lazy-load.jpg" alt="Lazy Loaded Image" loading="lazy"> </body> </html>Output:
Welcome to My Website
This is an example of using the image element in HTML.

