Search code examples
htmlhyperlinkpathlocalabsolute

Possible to create absolute link for local HTML file


Is this possible. From what I understand, absolute paths are most commonly used with links to a website. I am not using a web server, my HTML file is local and needs to be linked to another HTML file using an absolute link. These were my directions and any clarity is much appreciated, as I don't fully understand how I would do this yet. Thanks.

Directions:

  • Create a navigation (nav) menu pointing to the two HTML pages in the menu directory -The link to the menu page should be relative and point to the entrees section -The link to the health-warning page should be absolute.

Solution

  • It all depends on where the html file lives. If you're doing this locally then it'll depend on where the html file you're referencing is on your computer. If you're on windows that could be C:\Users\yourusername\projects\whateverfile.html while on Mac or Linux it would be file:///home/yourusername/projects/whateverfile.html. Those are absolute paths. A relative path is where the file is in relation to the html you're adding the link to. An example for your assignment could look like.

    <nav>
      <ul>
        <li><a href="./menu.html">Menu Page</a></li>
        <li><a href="file:///home/yourusername/projects/menu-project/health-warning.html">Health Warning</a></li>
      </ul>
    </nav>