Search code examples
htmlcompatibility

What is the best way to link homepage on a website


I should note that the website I'm working on is meant to be pretty simple.

The way I have my website files organized is that under one folder containing the entire website, I have the .html file for the home page, which contains links to different pages inside it for photos, videos, etc. Each of these pages have their own folders.

Attached here is the code I have for one of these pages, meant for my photos. I learned from this thread (Link not going back to home page) that if you just have:

<a href="/">Home</a>

That the link will take you back to the index/root directory. (Is this different from the home page? Sorry, I'm a noob.) Although, when I originally had it has just the code above, the link takes me to this weird gray page that just shows all of the files of my website (is that root place or whatever it's called?). Although, I see that I'm able to from there just simply add the .html file for my home page in that link directory, so the code I have now seems to work.

Is this an okay way to have a link to go back to the home page? Thank you for your time.

<!DOCTYPE html>

<html>
    <style>
        div.img {
  display: inline; 
  max-width: 650px;
}
    </style>
    <body>
        <div> <!--Home Button-->
          <a href="/homepage.html" style="float: right; margin-right: 100px;">
            Home
          </a>
        </div>

        <div class="img">
           <img src="1.jpg" width="384px;" height="384px;">
           <img src="2.png" width="384px;" height="384px;">
           <img src="3.png" width="384px;" height="384px;">
           <img src="4.JPG" width="384px;" height="384px;">
           <img src="5.png" width="384px;" height="384px;">
        </div>
    </body>
</html>

Solution

  • If it works and you are okay with having the path /homepage.html as your home page, then it is a perfectly good and logical way of linking back to the home page.

    As Kei mentioned in the comment, it is highly advisable to rename this file to index.html as most web servers and browsers will default to this file name as the root. For a lot of people, it's more desirable to just go to a domain (ie: mydomain.com) as the home page, rather than having to type in mydomain.com/homepage.html.

    All this to say, if you rename your home page file to index.html and serve this website through a web server of some sort (Apache for example), then you can simply use / as a path and it will bring you directly to the home page. I know that you mentioned that you are a beginner, so this may be slightly outside of the scope of what you are asking, but just letting you know for the future. Good luck!