Background Image Using CSS not Appearing [closed]

I am new to CSS and am trying to add a background image, and I can not seem to figure out why it doesn’t do anything. I am using code based on the tutorial in the following link

https://careerkarma.com/blog/css-background-image/#:~:text=The%20background%2Dimage%20property%20adds,image%20you%20wish%20to%20display.

in the section below the head and above the body of a html file in a Linux machine.

.image {
  background-image: url(https://images.pexels.com/photos/683039/pexels-photo-683039.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260);
  background-size: contain;
  height: 250px;
}
<div class="image"></div>

I know there are other questions about CSS background images, but I have looked at multiple ones and cannot seem to figure why they are not working on my system.

  • 2

    I can’t reproduce the problem.

    – 

  • I’ve changed your code to a Snippet. Its shows that the problem as described does not exist in this environment.

    – 




  • 1

    What do you mean by “in the section below the head and above the body”? You can’t have content after the </head> and before the <body>.

    – 

  • @Moob I didn’t know you can’t have content between the head and the body. Where would the best place to put this code in a typical html file be?

    – 

  • @Jack: There are a variety of options. But for this specific case the most common would be to put the <style> element inside the <head> element, and put the <div> element inside the <body> element.

    – 

Leave a Comment