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.
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:
- Using
RGB valuese.g. rgb(250,0,0), rgb(0,250,0), etc. - Using a
Hexadecimal(HEX) valuee.g. #FFFFFF, #000000, etc. - Using a valid
color namee.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 ©2026 Educative, Inc. All rights reserved