Back to Freecodecamp

Style the HTML Body Element

curriculum/challenges/english/blocks/basic-css/bad87fee1348bd9aedf08736.md

latest1.1 KB
Original Source

--description--

Now let's start fresh and talk about CSS inheritance.

Every HTML page has a body element.

--instructions--

We can prove that the body element exists here by giving it a background-color of black.

We can do this by adding the following to our style element:

css
body {
  background-color: black;
}

--hints--

Your body element should have the background-color of black.

js
const body = document.querySelector('body');
const backgroundColor = window.getComputedStyle(body)['background-color'];

assert.strictEqual(backgroundColor, 'rgb(0, 0, 0)');

Your CSS rule should be properly formatted with both opening and closing curly brackets.

js
assert.match(code, /<style>\s*body\s*\{\s*background.*\s*:\s*.*;\s*\}\s*<\/style>/i);

Your CSS rule should end with a semicolon.

js
assert.match(code, /<style>\s*body\s*\{\s*background.*\s*:\s*.*;\s*\}\s*<\/style>/i);

--seed--

--seed-contents--

html
<style>

</style>

--solutions--

html
<style>
body {
  background-color: black;
}
</style>