Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bigblueboss's avatar

Pointing CSS background image to the correct folder

In CSS when I have background: url('img/background1.jpg');

my CSS file is placed under public/img/ and now I realize that I've been assuming that the base starts from the public folder. Is that the case?

How, in my css, would I point to the public/img folder of mine? Or should I be pointing it to something else in the first place?

0 likes
3 replies
bigblueboss's avatar

I realize that when i start my path with "/" it seems to start me off at the public folder.

So I got the background image working, but I'm still wondering if this is the right way to point to things

For example, in my link tag, should I be doing href="/css/style.css" or is there a better way in L5? I see some ppl using HTML::asset. I saw in the official doc you can use asset().

Is there a best way?

mstnorris's avatar

@mk10shun That is how I would do it as all your assets should/would usually be in the public directory, so by using "/images/image_name.png" or whatever, then that would work fine (presuming you have an images directory within the public directory).

This is what mine looks like

public/
├── css
├── fonts
├── images
├── js
└── resources
taijuten's avatar

using the forward slash at the start will only work if your site is at the root of a domain.

I prefer to use

{{url('/images/imagename.png')}}

To ensure that everything will work regardless of where the site is

Please or to participate in this conversation.