Skip to content Skip to sidebar Skip to footer

Opening Another Page In Html

In my website, I have an html file inside of a folder, that is next to the index file. I want to add a link back to the index file. For example, the URL for the index would be, exa

Solution 1:

Assuming you have the following structure:

website.com/index.html
website.com/pages/example.html

You have three options -- two relative links, and one absolute link:

Relative to example.html:

<ahref="../index.html">Back to the index</a>

Relative to the root (note the slash):

<ahref="/index.html">Back to the index</a>

Absolute:

<ahref="http://example.com/index.html">Back to the index</a>

I'd recommend using a relative root, as your website URL may change in the future, so you don't really want to hardcode it.

As for which of the two relative approaches to use, relative to the root (/index.html) would be best in your base, as it will always take you back to the index -- you may move example.html to the same folder as index, or even a subfolder of pages, in which case the second relative link would need modification. If you have that link in multiple pages, that could prove annoying ;)

For further reading on relative and absolute URLs, I recommend checking out the Coffee Cup article.

Hope this helps! :)

Post a Comment for "Opening Another Page In Html"