Search code examples
htmltags

Can a "<a>" tag not use the ".." part when going up Folders to reach a file?


I just started learning HTML and CSS. I was using the tag, and I knew to use "../" when going up folders to a certain file, but when I removed the "..", I realized that the link would still work fine without any problems. My question is what is the use for it then?

I feel like the answer could be that the ".." is for the person looking at the code to know what's going on, but there might be another answer to this question. Please let me know.

Thanks


Solution

  • Given that you start at http://example.com/foo/bar/baz/doc.html:

    • other.html is a relative path and takes you to http://example.com/foo/bar/baz/other.html
    • ../other.html is a relative path that goes up one level and takes you to http://example.com/foo/bar/other.html
    • /other.html is an absolute path that replaces the whole path takes you to http://example.com/other.html

    ../other.html and /other.html only end up in the same place if you start one level or fewer deep.