Adding images to your HTML document can make it more visually appealing and engaging. Sometimes, you may want to add an image that is stored on your computer. In this blog post, we will discuss how to add an image from your computer to your HTML document.
Step 1: Locate the Image on Your Computer
Before you can add the image to your HTML document, you need to know the file path of the image. The file path should point to the location where the image file is saved on your computer. Make a note of the file path as you will need it in the next step.
Step 2: Add the Image to Your HTML Document
To add an image to your HTML document, you need to use the <img> element. The <img> element has a src attribute that specifies the source URL of the image. In this case, the source URL is the file path of the image on your computer.
Here’s the syntax for adding an image from your computer:
<img src=”file_path” alt=”description”>
Replace file_path with the actual file path of the image on your computer, and description with a brief description of the image. The alt attribute provides alternative text for the image if it cannot be displayed, which is useful for accessibility purposes.
Let’s say you have an image called “my_picture.jpg” in a folder named “images” within the same directory as your HTML file. You can add the image to your HTML document using the following code:
<img src=”images/my_picture.jpg” alt=”A description of my picture”>
Step 3: Save and Preview Your HTML Document
After adding the <img> element with the correct file path to your HTML document, save the changes and preview the document in a web browser. You should now see the image from your computer displayed on the webpage.
Adding an image from your computer to your HTML document is simple and straightforward. Just remember to use the correct file path and include the alt attribute for accessibility purposes. Happy coding!