Href & css folder path question

Hi, I’m curious about something.

Let’s say in my website folder structure I have folder called css and inside I have style.css file. I also have img folder and inside it I have image.jpg file.

When I use link - href I would put css/style.css to link html and css but it I want to use image as a background (background-image: url()) I would have to use ./img/image.jpg.

The question is - Why can I use img/image.jpg as a file path instead of …/img/image.jpg? I also can’t use …/css/style.css instead of css/style.css in that href file path.

Thanks for help.

Watch the dots one dot means one thing, two dots means another, there is no three dots. The URL after index.html is the same as the unix path.

You’re trying to use a relative path.

Google relative vs absolute path

If the index.html file and the css folder and the img folder are in the same folder then the stylesheet is css/style.css and the image is img/img.jpg

I didn’t even notice I used three dots in my post I meant to use two. I know what two dots means (outside of folder, right?) but I was wondering why I can’t use the same path in href as I used in background-image: url().
I’m gonna read up on absolute vs relative paths.

index.html , css folder and img folder are in the same folder but I still have to use ../img/image.jpg (in background-img: url() and css/style.css in

It’s like Main Folder and inside it are css folder, img folder, js folder and index.html

https://www.geeksforgeeks.org/absolute-relative-pathnames-unix/

Here is another link as well

1 Like

Thanks for the help guys, my mistake was that I forgot that the style.css is in css folder, which means that I should not be using the same path like when I’m editing index.html. Just me not paying any attention.