Home > Software design >  How do I add an image from another folder when my HTML file is in a different folder?
How do I add an image from another folder when my HTML file is in a different folder?

Time:03-19

For some reason, the image appears when I open it in notepad, but it doesn't work when I open my HTML file in VSCode. Adding the image in the folder of my HTML file and setting the source seems to work, but I don't want to do that. Could anyone help?

CodePudding user response:

You can simply change the path in the html tag to wherever you need:

<img src="../OTHER_FOLDER/IMAGE_NAME.png" />

The .. lets you move up one folder in the systems file hierarchy.

CodePudding user response:

If your image is located in the folder one level up from the folder in which is index.html you can use

<img src="../image.jpg">

Else you can use absolute path:

<img src="C:\Users\your_user\picture.jpg"```

CodePudding user response:

use ../ with src="" like this

<img src="../pictures/pic.png" alt="Image 01">
<img src="../../pictures/pic.png" alt="Image 01">
  •  Tags:  
  • html
  • Related