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.

Syntax

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.

Example

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

Output

How to change background color in CSS




Contact US

Email:[email protected]

How to change background color in CSS
10/30