Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsNode/Express: help understanding how servers and files work
So I have an index.html file that links to a style sheet:
<link rel="stylesheet" href="css/style.css"/>
I can open up index.html in the browser and view it just fine.
But if I write it like this:
<link rel="stylesheet" href="/css/style.css"/>
with the forward slash at the beginning of the url, it won't load the stylesheet this way. I have to start up a server in order to have the css come through in the browser.
What's the difference between the url with and without the forward slash? Why does it behave differently, and which method is best in real life?
1 Answer
Jonathan Grieve
Treehouse Moderator 91,253 PointsFor the link tag it's best practice noto include a preceding forward slash. Remember it's a path to the file relative to the location of the HTML file.
Putting a forward slash in makes it an absolute path, :-)