Take the 2-minute tour ×

When I reference an image or other file in a CSS file by a relative path, is the path relative to the CSS file or the HTML file using the CSS file?

share|improve this question

2 Answers 2

up vote 38 down vote accepted

Yes, it's relative to the .css

Here's an example layout:

Page:  page.htm ... does not matter where
CSS:   /resources/css/styles.css  
Image: /resources/images/image.jpg

CSS in styles.css:

div { background-image: url('../images/image.jpg');
share|improve this answer
Perfect, thanks. Just what I needed to know. –  Nathan Osman Apr 27 '10 at 4:03
Thank you for the detailed answer. I was really confused in the same issue, and here you just solved it in a better way. –  AbdulAziz Feb 28 '12 at 13:45
This is indeed reasonable, because it allows referencing the same .css file from different .html files (which may be located in different places) without braking paths to external objects. –  Davide Mar 4 at 14:06

To the CSS file.

share|improve this answer

Your Answer


