Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Basics Images, Text and Links Understanding File Paths

marcos rodriguez
marcos rodriguez
1,214 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
seal-mask
.a{fill-rule:evenodd;}techdegree
Jacob Jackson
UX Design Techdegree Student 7,833 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