Trusted answers to developer questions

How do you change the background color using CSS?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

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.

RELATED TAGS

css
color
css background color
background
html
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?