Search code examples
htmlurlhyperlinkrelative-pathabsolute-path

How to access root directory in html?


I am just beginning HTML and I wanted to know how to use root directory in HTML?

I have a css and js folder in the root directory and I linked it(using relative URL) for the index.html in that directory. But now I have a subdirectory called foo along with the css and js sub-directory's. Now in the foo folder I cannot use relative URL because the css folder is not in that directory.

Do I have to use absolute URL, or is there a way to use /code_for_main_dir/css


Solution

  • Path starting with / means root directory.

    <link rel="stylesheet" type="text/css" href="/css/mytheme.css">
    

    More info: https://www.w3schools.com/html/html_filepaths.asp