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 trial

CSS CSS Basics (2014) Getting Started with CSS Introduction to CSS

I still am having a lot of trouble understanding the difference between RELATIVE and ROOT-RELATIVE paths.

I'd like to understand when/why you'd use one over the other. I am not understanding what this means: "Root-relative paths are commonly used when building and testing sites directly on the web or on a local web server." Because aren't you doing that same thing when using relative paths too?

5 Answers

Kevin Ohlsson
Kevin Ohlsson
4,559 Points

Everything starts at the root, just like how a seed becomes the the roots of a tree root relative is a way to navigate to a file from the root relative paths is a way to navigate to a file from the current directory via the root to another file

navigate from the root directory to the folder "whales"

/whales

navigate from our current directory to the folder "whales" via the root folder

../whales

Its the same end-result, we get to the same file, but root relative and relative paths are different ways to get where we want.

one final example Imagine you are climbing a tree. You start at the root and then you go up to a bransch to see the view of the landscape. Then you go down.

Our climb might look something like this if we were to look at it hierarchically.

/root/trunk/bransch/

This path describes how we got to where we are and in what order we got there.

If we want to go back down to the ground we need to go back via the trunk.. and so on.

Root relative paths would mean that insteaf of going back to the original path we are zapped down to the ground right away. Its like we invented a portal to go from one part in our hiearchy to a view that is closest to the root view in an instant.

As guil pointed out in the video about root relative paths, you need to have a server to serve a webpage using root-relative paths. Only servers can create a root folder for visitors to access contraty to your file system which has its own root that you as a user dont define. Changing your operating system folder structure would most likely break your computer. Its easy to break a linux system because it is easy to change the directory structure into something unrecgonizable for the linux operating system, thus making a computer unbootable.

Gari Merrifield
Gari Merrifield
9,597 Points

You may want to watch Guil's video, if you have not already : https://teamtreehouse.com/library/rootrelative-paths

Root relative, refers to root of the web server. So "/css/style.css" would mean "look in the css folder, that is under the webroot" Depending on the OS and webserver software you are using, this can vary somewhat. For example, a default install of Ubuntu's server with Apache would likely have the root at "/var/www/html" so the root relative "/css/style.css" would equate to "/var/www/html/css/style.css"

A strictly relative path would mean that you are using "../" as a means to go up one folder level from where your file resides, so if you have your HTML file under "/var/www/html/pages/" you could use "../css/style.css" to get to the file at "/var/www/html/css/style.css"

However, if you are testing on your local computer WITHOUT a web server, "Root-relative" is rather pointless, as there is not a "webroot" defined.

shuai zhao
shuai zhao
2,122 Points

thank you ! thats very helpful !

The link you posted above, http://www.webdevbydoing.com/absolute-relative-and-root-relative-file-paths/ was the best explanation I've seen anywhere. Thank you.

MEHDI ELAZZOUZI
MEHDI ELAZZOUZI
1,204 Points

I had the same problem but I will give you the summary

if you work in any server local or internet and use relative-root Will not get any problem

but if you work in your simple pc with editor and browser do not use it you should use relative because the browser in this case do not understand relative-root

i hope that I have given you a clear answer

shuai zhao
shuai zhao
2,122 Points

thank you , it makes a alot sense now .

Edward Davies
seal-mask
.a{fill-rule:evenodd;}techdegree
Edward Davies
Front End Web Development Techdegree Student 1,367 Points

The key difference is that root-relative paths are used with a web server only.

Relative paths are different because you can also use them when testing locally, whether you're using a web server or not.

It is better to use relative paths because you can use them with or without a web server and your links will not be broken when working locally.