HTML HTML Basics Images, Text and Links Understanding File Paths

marcos rodriguez
marcos rodriguez
1,213 Points

So when do I use "href=../" and "href=(folder name)/page.html" ??

So I just want to clarify, if the two html pages are in the same folder you can link the page with just the file name? But if they are in separate folders, then you use the "../"? I will set up an example to detail my question more.

Let's say the main folder name is main and the sub is main.html. Now, if there was another existing sub in that same folder titled index.html, then in order to link main.html too index.html I would use:

<nav> <ul> <li><a href="index.html">Home</a></li>

Clicking on home will redirect you to index.html correct?

Now this is if I want to link the pages but they are not in the same folder and the html I am linking from is a sub.

<nav> <ul> <li><a href="../index.html">Home</a></li>

Ok, now this one is if I am in an html page outside of a folder trying to link into a folder. We will leave main as the folder title followed by index.html as the sub.

<nav> <ul> <li><a href="main/index.html">Home</a></li>

Sorry for the long question. Trying to understand it well. Thank you!

1 Answer

Jacob Jackson
Jacob Jackson
UX Design Techdegree Student 7,799 Points

Hi Marcos!

Great question, it can be a little tricky but it looks like you have it down.

Basically if you acknowledge that "/" is to go into a folder and "../" is to come out of a folder, you'll be in great shape :)

You seem to have it figured out, but here is a short example to confirm your thoughts:

https://www.w3schools.com/Html/html_filepaths.asp

Hope you find this useful!

Keep it up and good luck! -Jake