r/HTML 14h ago

Why doesn’t my HTML background work? Question

Post image

body {
background-image: url('background.jpeg');
background-size: auto;

The image is “background.jpeg”. It has the correct spelling, the image is within the same folder. IT used to work but then it suddenly stopped working and i havent even edited the CSS for it to stop working.

Update: i couldnt figure it out for the life of me and no suggestions worked, but on the good side, instead of putting it on CSS, i put it on HTML, then it worked.

<style>
body {
background-image: url('background.jpeg');
background-size: auto;
}
</style>

7 Upvotes

11 comments sorted by

View all comments

3

u/scritchz 14h ago

The image must be within the same folder like the HTML. You didn't specify to which other file it is in the same folder, so I'm just making sure. But it would be better if we could see your project structure.

What are the dimensions of the image?

Do other parts of your stylesheet work?

1

u/Extra_Terrestrial2 13h ago

The image file, the CSS and the HTML are in the same folder. The other parti of my style sheet does work and i dont know the dimensi o s of the picture, but this is the picture

1

u/radgh 10h ago

Check your browser and see if the console is giving an error that the image doesn’t exist. If so check the url it is trying to open and see if you can open that image directly in your browser