skip to Main Content

I put a background url in my CSS inside body and connected the CSS file to the html file, but nothing shows on google. I’m 100% sure I have the right path to the image. But the image is in the path I coded and I have no clue why it says file not found.

body  {
    background-image: url("/CSS/Images/barcelonastadium.jpg");
  } 

GET file:///C:/CSS/Images/barcelonastadium.jpg net::ERR_FILE_NOT_FOUND

That error shows in console log even tho the file exists.

HTML Code:

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title> Barcelona </title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='./CSS/home.css'>
</head>
<style>

</style>
<body>
    <h1> Barcelona </h1>
</body>
</html>

folder

2

Answers


  1. Your file path as seen in GET file:///C:/CSS/Images/barcelonastadium.jpg net::ERR_FILE_NOT_FOUND has two protocols in it: file and C. You should use a relative path in your CSS file instead, to avoid the confusion:

    ./CSS/Images/barcelonastadium.jpg or ./Images/barcelonastadium.jpg

    Login or Signup to reply.
  2. You can use an absolute or relative path.

    Here’s a relative path:

    body  {
      background-image: url("./Images/barcelonastadium.jpg");
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search