Directory link structure - /css/my.css VS css/my.css

Need some clarification … in most examples online I see the first relative link … /css/my.css.

I can’t do that though, my system doesn’t recognize such a link. I remove the preceding slash to make the page work again.

What’s the difference & is one better than the other?

The slash at the beginning signifies “from the root directory” and without signifies “from the current directory” eg. with

From the index.html page, either /css/my.css or css/my.css would work as index.html is directly under the root.

But from page.html, /css/my.css would work, but css/my.css would not. However, …/css/my.css would (…/ = “backout” of the current directory).

Essentially using the “from under the root” slash makes it a bit easier to have relative paths without worrying about getting the depth correct.

While what’s been stated above is entirely correct, it’s worth stating that your system as you mentioned will not understand the proceeding slash as it signifies a root directory (which your system won’t be able to establish). What I do is omit the slash (for the benefit of local previews) and use a htaccess file with path “shortcuts” applied to direct all relative links from the base directory (ensuring everything works as required). :slight_smile: