htmlanchorhref

HTML: anchor attribute when pointing to index file


Considering leaving the href attribute empty for anchor tags is not a best-practice, how do I go about doing that "legally"?

I don't want to link to index.html or index.php or such, I want to link to the default index file in that document.

Setting it to / does the trick if you are in the root, otherwise it will still go there so it's not a solution.

How should I do this?

Thank you.


Solution

  • If you wish to link to the default document at your current directory, this should be valid:

    <a href="./">My Directory's Default Document</a>
    

    If you just wish to have an anchor tag that does not leave the current page:

    <a href="#">Go Nowhere</a>