Problems Inserting Background Images in CSS


See,the problem is as simple,but i can’t handle it. The thing is that i want to set an image as the background in CSS,and for that,im typing this code-

h2{ font-size:40px;
color: black;
alignment: center;}
body{background-image:url(“location of the image(copied from “properties”)/filename.extension”);

So the actual problem is that the image is already stored in my computer. So to apply it as the background image,im using the method written above. But its not helping. I can’t see any background image if i enter the location of the image and then type the filename after a “/”.

So please tell me the correct way to use a locally stored image as a background image in CSS.

You need to use absolute or relative path for the image. If the image is stored within the same directory as the css file, you could use a relative path which consist of only the file name + file extension

the forward slash is used *nix based systems within the path, for windows, this is backslashes.

for example, for windows you could do an absolute path:


or a relative path:


this will look for the images in the current directory (in which the css file is located), and then inside images directory look for a file named desired_image.jpg

Bro/sis,I’ve already tried it,turning backslashes into forward ones,just the way u told.

So shall i use forward slashes or backward ones?

this depends on the operating system you are using.

What kind of path are you you using? absolute or relative?

how is the file structure of your website?

Im using absolute path…

Can i see it? Copy the path you typed for the url into the file explorer to ensure you got it right.

Sorry,i Can’t show it to you but here’s what its like(except personal details):
C:/Users/“microsoft account username”/Desktop/PHOTO/134___10/IMG_5538.jpg

lets repeat myself: you are using windows, as such, in the path, backward slashes should be used, not forward slashes

i clearly see you use forward slashes in the path

Did you take the other step i asked of you? copy this path into the windows file explorer (yes, we can type the path in there, which means we can also paste) to see if it actually the directory exist, which if you would have done, would have thrown an error

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.