CSS Background Color

The CSS background-color property allows you to set the background color of an element. It can be used on almost any HTML element to enhance visual presentation.

Key Points on CSS Background Color:

Syntax for CSS Background Color:

Syntax Example


        /* Syntax for background-color */
        .background-color: color_value;
                
        /* Example */
        .background-color: #ffcc00;

Examples of CSS Background Color:

The following examples demonstrate the usage of the background-color property:

Code Example: Background Color using Hex

div {
            background-color: #ffcc00;
        }

Output

This div has a background color of #ffcc00.

Code Example: Background Color using RGB

div {
            background-color: rgb(255, 0, 0);
        }

Output

This div has a background color of red using RGB.

Code Example: Background Color using RGBA

div {
            background-color: rgba(0, 255, 0, 0.5);
        }

Output

This div has a semi-transparent green background.

Common Values for Background Color:

Using the background-color property effectively can create contrast, enhance readability, and improve the design of your web page.