My Background Image Isn't working CSS


#1

And my coding is as follows:

<!doctype html>

Fake Ad * {box-sizing: border-box;} .body {background-image: url (hello.jpg);

Hello

I have no clue why my background image isn’t working, I need to finish this website in two days for a school project and this is not a good start! Please help! :disappointed_relieved:


#2

Ok first if this is all your code then you are doing it wrong, this is how you make the structure:
(!doctype html is not needed btw)

<html>
<head>
</head>
<body>
</body>
</html>

Also, this code needs to be in the head with <style> here’s how:


<html>
<head>
<style>
{box-sizing: border-box;} .body {background-image: url (hello.jpg); 
</style>
</head>
<body>
</body>
</html>

(I don’t know why the code is red)
also im not very good at CSS but I have a feeling somethings wrong with the code,
shouldn’t be like:

body {
     ???
}

sorry im not an expert :frowning:


#3

So lets assume that we want to set up a simple webpage with a background

You would normally start with a

DOCTYPE is good practice (though it isn’t required) as the tag tells the browser that we are using html5 and not older html versions.

Next, we want to set up the general webpage structure.

Now with that done, you should use css to make your background appear. Note: This is done within the style tag

body {
background-image: url(hello.jpg);
}
Now notice how I didn’t put the period? That is because the period would indicate that we are styling a class, in this case we are not. We are, however, styling the body tag.
This is mainly all that is wrong with your css code compared to mine. Happy Coding!


#4

You are right! DOCTYPE isn’t required, however, the doctype tag (which has to be capitalized) declares the version of html we are using.


#5

You are definitely right about that.