Defining Images in HTML
In HTML, images are defined using the <img> tag. This tag is used to embed an image in a
webpage.
It is a self-closing tag, meaning it does not need a closing tag. Here is the basic syntax:
<img src="image.jpg" alt="Description of image" width="300" height="200">
Key Attributes:
- src (source): The path to the image file (required).
- alt (alternative text): Text to display if the image cannot load (important for accessibility and SEO).
- width: The width of the image (optional, in pixels).
- height: The height of the image (optional, in pixels).
Example:
<!DOCTYPE html>
<html>
<head>
<title>Image Example</title>
</head>
<body>
<h1>My Favorite Dog</h1>
<img src="german-shepherd.jpg" alt="A brown German Shepherd" width="400" height="300">
<p>This is a picture of a German Shepherd.</p>
</body>
</html>