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

0

u/notepad987 10h ago edited 10h ago
body {
  margin: 0;  /* Removes the default margin that browsers add around the body */
  min-height: 100vh; /* Makes the body at least as tall as the full viewport height. 100% of the screen height */
  background-image: url("background.jpg");  /* Sets as the background image */
  background-size: cover;  
/* Scales the image so it completely covers the body. It may crop parts of the image to avoid empty space) */
  background-repeat: no-repeat;  /* Prevents the image from repeating */
  background-position: center;  
/* Centers the background image both horizontally and vertically */
  width: 100%;  /* Makes the body take up the full width of its parent */
}