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

HTML

I am finding quite stupid how they are using file paths like ../../img/whatever.jpg when /img on its own works fine.

I am finding quite stupid how they are using file paths like ../../img/whatever.jpg when /img on its own works fine no matter how many folders deep the html file or image is.

Cant we just have /img/whatever.png for locating images?

1 Answer

Steven Parker
Steven Parker
231,261 Points

The advantage of relative paths is that the entire folder structure could be moved and things would still work. Absolute paths are "brittle", and the code might break when everything is moved.

Thank you for commenting that makes sense.. what if i have over a hundred files because articles are have different folders for the years and then I need to use the ../../ how am i going to know how many to do?

Steven Parker
Steven Parker
231,261 Points

The path is the same whether the folder contains one file or a hundred. Each path reflects the relationship between the current directory and the one where the resource is located.