How to Go Back to the Root Directory Using HTML

How to Go Back to the Root Directory Using HTML thumbnail
Use relative paths to point to the root directory without typing entire URLs.

Some HTML tags require file paths to grab images, style sheets, scripts and other content. Anchor tags -- the tags that build hyperlinks -- also require file paths. Two types of file paths exist: absolute and relative. In relative file paths, you can go back to the root directory of your website without typing out the entire URL. Three methods exist for pointing relative paths to the root directory. Select the one that best suits your needs.

Instructions

    • 1

      Place two dots before a backslash to go up a directory in your "href" or "src" paths. Repeat the dots and backslash combo as many times as you need to reach the root directory. For example, to go back up to the root if the Web page is two directories down, write your path like this:

      <a href="../../home.html">Go Back to Home</a>

    • 2

      Place only a backslash at the beginning of the file path to jump directly to the root. This works the same as the other example and is quicker, though it does not show how many directories the path is moving through. Here is an example:

      <a href="/home.html">Go Back to Home</a>

    • 3

      Set a base directory in the head of your HTML file in order to point all links on the Web page to the root directory. Use the base tag to accomplish this. The tag looks like this:

      <base href="http://yourdomain.com/" />

      Place your domain name between the double-quote marks following "href" to set your Web page to the root directory. Close the tag with a backslash at the end when writing for the XHTML specification; otherwise, this is unnecessary but will not affect how the page works.

Tips & Warnings

  • Always back up your HTML files before editing them.

Related Searches:

References

  • Photo Credit Jupiterimages/Polka Dot/Getty Images

Comments

You May Also Like

Related Ads

Featured