Javatpoint Logo
Javatpoint Logo

How to change background color in CSS?

The background-color property in CSS is used to set the background color of an element. It applies solid colors as the element's background. The background of an element covers the total size, including the padding and border, but excluding margin. It can be applied to all HTML elements.


The color_name value of this property defines the value of background color or specifies the color codes. It can be given by using the color name, rgb() value, or the hexadecimal value.

The transparent value of this property is the default value, which specifies the transparent background color.


In this example, we are defining the value of the background-color property by using the color name, hexadecimal value, rgb() value, and the hsl() value. There are four div elements on which we apply the background-color property.

Test it Now


How to change background color in CSS

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA