Unable to link current file to other relative file using href attribute

Can someone help as I have been trying for a few days to link a relative image file using the href attribute to my current file by placing the name of the folder before the file name with a forward slash before it, but it’s not been working please assist

Bro, give absolute URL from the Web. Or Make like “./HTML Code/Vacation.jpg”

1 Like

The problem occurs due to it can’t find the image on a given path. You trying to access the image in another folder. You have to use two full stop .. followed by forward slash / followed by folder name and image .

Solution:
<a href='../HTML code/vacationbeach.jpg'>Page 3</a>

1 Like


Issue still persisting , I even tried removing some extensions to see if that would make a difference but no change

If you want to turn an image into a link, follow the rule:

<a href="URL"><img src="URL"></a>

This is guidance.

At the moment you have a link that leads nowhere.

P.S.
If you only want to add the picture from your image folder, then use the img element in order to see that image on the page:

<img src="URL"><a href="URL">Page 3</a>

and add the hyperlink to the text “Page 3”. In this case, the ‘href’ attribute should have the URL of another HTML page…

I suppose this is your intention if I understood your goal well.

I’m not sure if you actually want a link that links to an image but technically, it should work.

But you have a new line in front of the image file extension (jpg), which won’t work. It should be href="../HTML code/vacationbeach.jpg all on the same line.

I am actually trying to follow the steps on linking files together from the video here , i realized by using the absolute url alone it works and i see th image fine but thats not the way how the tutorial shows it around 1:05:49

Well im just experimenting with the attribute to see how it works being that I am relatively new at coding , i tried to change the file to html file and it still brings the same error

The code should work, I’m pretty sure it has to do with how you have opened the folders (added to the workspace) and started the live server.

Close the server and the workspace. Put the two folders inside a common folder, now open the common folder in VS Code. Select the index HTML file and click the live server button.

/web
  /lesson (open this folder)
    /HTML lesson 2
	  index.html (select this file and run Live Server)
    /HTML code
	  about.html
1 Like

Thanks man it finally worked

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.