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.

New on Educative
Learn any Language for FREE all September šŸŽ‰
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
šŸŽ GĀ iĀ vĀ eĀ aĀ wĀ aĀ y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved