Adding an image to an HTML document can enhance its visual appeal and provide additional information. Here, we'll guide you through the steps of adding an image using HTML.

Before we dive into the code, let's understand that images in HTML are inserted using the <img> tag. This tag requires an 'src' attribute, which points to the image file's location.

Inserting an Image: The Basics
The basic syntax for the <img> tag is as follows:

<img src="image_url" alt="alternative_text">
The 'src' attribute is mandatory and holds the image's URL. The 'alt' attribute is optional but recommended. It provides an alternative text description for the image, useful for accessibility and when the image fails to load.

Absolute vs. Relative Paths
You can use either an absolute or a relative path for your image's URL. An absolute path starts from the root directory of your website, while a relative path starts from the current directory.
If your image is in the same directory as your HTML file, you can use a relative path like this: <img src="image_name.png">. If it's in a different directory, you might need to use a relative path with dots and slashes, like this: <img src="../images/image_name.png">.

Image Sizes and Alignment
By default, an image will maintain its original size. However, you can control its size and alignment using the 'width' and 'height' attributes, or the 'style' attribute for CSS.
For instance, to set the image's width to 300 pixels and height to auto, you can use: <img src="image_url" style="width:300px;height:auto;">. To align it to the right, use: <img src="image_url" style="float:right;">.

Practical Examples
Let's consider a case where you want to display an image of a sunset on your webpage. First, ensure the image file (sunset.jpg) is uploaded to your server at 'images/sunset.jpg'.




















Then, you can insert it into your HTML document like this:
<img src="images/sunset.jpg" alt="A beautiful sunset">
In this case, if the image fails to load, visitors will see the text 'A beautiful sunset' instead.
Adding Captions with FIGURE and FIGCAPTION
If you'd like to add a caption to your image, you can use the <figure> and <figcaption> tags. Here's an example:
<figure> <img src="images/sunset.jpg" alt="A beautiful sunset"> <figcaption>Captivating colors of a sunset</figcaption> </figure>
And there you have it! You've now learned how to add images to your HTML documents, along with various ways to control their appearance. Happy coding!