How do you change the background color using CSS?

In CSS, we use the background-color property to specify the background color of an element.

svg viewer

In the code snippet below, the entire color of the web page is set using the background-color property.

The value of the background-color property can be specified in three ways:

  1. Using RGB values e.g. rgb(250,0,0), rgb(0,250,0), etc.
  2. Using a Hexadecimal(HEX) value e.g. #FFFFFF, #000000, etc.
  3. Using a valid color name e.g. “white”, “red”, “black”, “blue”, etc.

The code snippet below sets the background color for the entire body, <div>, <h2> and <p> elements of the web page.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved