Search code examples
htmlanchor

trying to link to index.html from another html page deeper in the folder structure


I'm trying to get something basic to work here. I have an index page in my root and another folder called collections. Within collections, I have another folder 'MA' that has 'MA.html'. All I want to do is link MA.html back to index.html. I have an anchor link 'back' that tries to do so but on clicking it just reloads MA.html again. I'm still new to web dev so go pls go easy on me. I am adding an image of my folder structure.

enter image description here

Here is my HTML -

<div class="info overlay">
     <div class="text">
        <a href="/collections/MA/MA.html">MA</a>
        <a href="/collections/capsule.html">Capsule</a>
        <a href="/collections/BA/BA.html">BA</a>
     </div>
     <a href="/index.html" class="info-back">Back</a>
  </div>

Solution

  • In index.html

    <a href="./collections/MA/MA.html">MA</a>
    

    That's the same as before, once you land on MA.html, you want to go back to index.html So-

    In MA.html

    <a href="../../index.html">link</a>
    

    The .. (double dots) mean 'go up a directory level'.