To add an image to an HTML document, follow these steps:
- First, save the image file in a location that is accessible to your HTML file, such as in the same folder or in a subfolder.
- Use the <img> tag to insert the image into your HTML file. The <img> tag is a self-closing tag and does not require a closing tag.
- In the <img> tag, specify the src attribute and set its value to the file path or URL of the image file.
- You can also include other attributes such as alt and title to provide additional information about the image for accessibility and SEO purposes.
Here is an example of how to insert an image into an HTML file:
<title>Adding an Image to HTML</title>
<img src=”path/to/my-image.jpg” alt=”A beautiful landscape” title=”My favorite place to go hiking”>
In this example, the image file “my-image.jpg” is located in the “path/to” folder. The alt attribute describes the image for users who cannot see it, and the title attribute provides additional information about the image when the user hovers over it.