Learn
CSS Color
Foreground vs Background

Before discussing the specifics of color, it’s important to make two distinctions about color. Color can affect the following design aspects:

  1. The foreground color
  2. The background color

Foreground color is the color that an element appears in. For example, when a heading is styled to appear green, the foreground color of the heading has been styled.

Conversely, when a heading is styled so that its background appears yellow, the background color of the heading has been styled

In CSS, these two design aspects can be styled with the following two properties:

  1. color - this property styles an element’s foreground color.
  2. background-color - this property styles an element’s background color.
h1 { color: Red; background-color: Blue; }

In the example above, the text of the heading will appear in red, and the background of the heading will appear blue.

Instructions

1.

In style.css, set the foreground color of the h1 heading to MidnightBlue.

2.

Next, set the background color of the h1 heading to Aqua.

Notice that the background-color property did not change the background color of the entire page. Instead, only the background area behind heading changed. We’ll learn why this occurs in more detail later in the course.

Note: The background color of the heading will block the image of the coffee.

Folder Icon

Take this course for free

Already have an account?