Here's a guide on how to use the <img>
tag in HTML along with a code example:
The <img>
tag is used to embed images in an HTML document. It is a self-closing tag, which means that it doesn't require a closing tag.
Here's the basic syntax for using the <img>
tag:
html<img src="image.jpg" alt="Image description">
Let's break this down:
- The
src
attribute specifies the URL of the image you want to display. This can be a relative or absolute URL. - The
alt
attribute provides a text description of the image. This is important for accessibility purposes, as screen readers can read the text description to visually impaired users.
Here's an example of how to use the <img>
tag:
html<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to my web page!</h1>
<p>Here's an image:</p>
<img src="https://example.com/images/cat.jpg" alt="A cute cat">
</body>
</html>
In this example, we're displaying an image of a cat with a URL of https://example.com/images/cat.jpg
. We've also provided a text description of the image using the alt
attribute.
I hope that helps! Let me know if you have any more questions.