Jessica Bell
Jessica Bell

Reputation: 11

how do i add an image in the background in css from a folder?

I have an image, and from what I've seen in W3schools you can just use
body background = farm.jpg
And that works, but it says and I've seen people say this, that it can work with css with

background-image: url(farm.jpg) (with and without quotes)

yet whenever i try it can't find the picture.Do I need to put it in a separate folder?

Upvotes: 1

Views: 1651

Answers (2)

M14
M14

Reputation: 490

(1) https://www.w3schools.com/tags/att_body_background.asp

Unfourtunately the background attribute is not supported in HTML5. You must use CSS instead.

(2) You can use the code example form this page, what works:

https://wiki.selfhtml.org/wiki/CSS/Eigenschaften/Hintergrundfarben_und_-bilder/background-image

For example:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Your page</title>
  <meta name="description" content="The HTML5 page">
  <meta name="author" content="Your Name">
  <link rel="stylesheet" href="css/styles.css?v=1.0">
  <style>
      body {
        background-image: url("background.png");
      }
  </style>
</head>
<body>
  <p>Test.</p>    
</body>
</html>

Hope this helps.

Upvotes: 0

Saleh Mosleh
Saleh Mosleh

Reputation: 544

It depenteds to where is your css file , put your css file and image file into same place, and try below

background-image: url("frame.jpg");

Or you can use / to start from root folder.

background-image: url("/frame.jpg");

Read this.

Upvotes: 1

Related Questions