Example: Relative Links

Recipe Book Website Structure

Below is a diagram of the structure of the Recipe Book website. For the sake of this example, not all pages are included.


From index.html

Assume we are working in the root level index.html page.

Link to recipes.html: Answer

These files are in the same folder, so we just need to use the file name.

<a href="recipes.html">Recipes</a>
Link to mango.html: Answer

mango.html is inside the tips folder. Both the index.html and tips folder are at the root level of the site.

<a href="tips/mango.html">Mango</a>
Link to mango-chutney.html: Answer

mango-chutney.html is inside the recipes folder. Both the index.html and recipes folder are at the root level of the site.

<a href="recipes/mango-chutney.html">Mango Chutney</a>

From mango-chutney.html

Now assume we are working on the mango-chutney.html page.

Link to index.html: Answer

Both the index.html and recipes folder are at the root level of the site. To get to index.html from mango-chutney.html, you have to go up one level in the hierarchy (../)

<a href="../index.html">Home</a>
Link to mango-salsa.html: Answer

mango-salsa.html is in the same folder as mango-chutney.html so we just need to use the file name.

<a href="mango-salsa.html">Mango Salsa</a>
Link to mango.html: Answer

mango.html is inside the tips folder. Both the tips folder and recipes folder are at the root level of the site. To get to mango.html from mango-chutney.html, you have to go up one level in the hierarchy (../) and then inside the tips folder.

<a href="../tips/mango.html">Mango</a>