w3resource
HTML exercises

CSS Properties: How to set the background-color of different elements?

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<meta type="utf-8" />
<title>How to set the background-color of different elements</title>
<style type="text/css">
body {
    background-color: #00CCFF;
}

h1 {
    background-color: #bbff00;
}

p {
    background-color: rgb(255,0,255);
}
</style>
</head>
<body>
<h1>This is heading 1</h1>
<p>This is a paragraph.</p>
</body>
</html>

Live Demo:

See the Pen background-color-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes No

Go to Exercise page

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming