The answer also has some dependency on whether or not the site is being developed and tested locally or if your publishing your content to a web server and testing links on the Live Site.
If your href
attribute's URL is using a Relative URL and has a domain name being mapped to your Document Root on a Live Site, the above answers are correct.
However, if your testing your links where all the files are on a local PC's file system where no web server is being used locally, then you might find the following information helpful too.
If you are testing locally, there is usually no domain associated with your Document Root
and the pathing changes in a number of ways.
- If you link to a file in any child directories, you will NOT have an initial slash ("/") in your
href
or in this case a src
attribute because there is no domain and the Relative URL is relative to the current page. (The same rules apply to your href
URLs as well)
Local testing URLS:
<img src="images/image-1.jpg" alt="my-Image-1">
..as opposed to a Relative URL on a page in a Live Site that has a domain name where you WOULD use an initial forward slash because it will be relative to the domain.
Remote Live Testing:
<img src="/images/image-1.jpg" alt="my-Image-1">
I am aware this is not the situation you ask about but it should help with the following two examples where the folders are adjacent and parent directories on a local file system. Your situation is that your Relative URL is to a file located in an adjacent directory. See below if your developing and testing locally.
- For Relative URLs linking to your css stylesheet files in an adjacent directory or even links to files a parent directory above your current page on a local filesystem (usually without a domain), your
href
attribute URL pathing should use a double-dot-slash (../
). So your situation (if testing locally without a domain) is:
<link rel="stylesheet" href="../css/basic.css" type="text/css" media="screen" />
...as indicated by @Cory Dolphin above.
I experienced this and found that my issue was that I kept finding different results depending on where I was testing and it was driving me mad.
I originally thought the pathing difference had to do with my local files being on my local Windows system and the reason it was slightly different was becuase of the file system of my remote Linux Apache VPS.
I found that it has more to do with whether it has a domain mapping to your site files or not. This is addressed somewhat in W3Schools.com's Page in the section that's titled The src Attribute and Relative URLs.