Adding a Background

The pages you’ve created so far have a white background, or more exactly,
they have the default background chosen by the browser. In old versions of
web browsers, that background color was gray. You can change the color of
the background using CSS, or use a background image.
Background colors and background images can be applied to the entire
page or to individual elements. Changing background colors on individual
elements helps to add highlight and color to certain areas of the page.

Changing the background color
The background color of an HTML element is changed with the backgroundcolor CSS property. The background color uses the same syntax (hex code)
as font colors; refer to the discussion of font colors earlier in this chapter to
see hex codes for common colors.
Here’s an example that changes the background color of the entire page:


body {
background-color: #FFFF00;
}


Adding a Background
Adding
a yellow
background
color to a
page.
As previously stated, individual elements can also be changed and you can
use all the different CSS selectors to focus that color change to a class, to
an individual element (using an id), or to all elements by using the element
name. For example, changing all the
<div> elements to yellow looks like
this:
div {
background-color: #FFFF00;
}
You can also use CSS to target elements by their hierarchy; in other words,
you can target the elements when they appear as children of other elements.