Home CSS CSS Background-color

CSS Background-color

Beginner ⏱ 6 min read Updated: Jul 2026
  • The background-color property is used to set the background color of an HTML element.
  • It can apply colors to elements like body, div, headings, buttons, and sections.
  • CSS background colors can be defined using color names, HEX, RGB, RGBA, HSL, and transparent values.
  • This property helps improve website design and user experience.

What is CSS background-color?

The CSS background-color property is used to define the background color of an element. It adds a color behind the content area of HTML elements.

You can use the background-color property to style complete webpages, containers, navigation bars, cards, buttons, and other UI components.

CSS background-color Syntax

selector { background-color: value; }
Example


body {

    background-color: 
    lightblue;

}

Setting Background Color Using Color Name

CSS provides predefined color names that can be directly used as background colors. Examples include red, blue, green, yellow, and many more.

Example


div {

    background-color: 
    yellow;

}

Background Color Using HEX Value

HEX values represent colors using hexadecimal numbers. They start with a hash (#) symbol followed by six characters.

Example


h1 {

    background-color:
    #3498db;

}

Background Color Using RGB Value

RGB values define colors using Red, Green, and Blue components. Each value ranges from 0 to 255.

Example


p {

    background-color:
    rgb(255, 0, 0);

}

Background Color Using RGBA

RGBA is an extension of RGB that includes an alpha value. The alpha value controls transparency between 0 and 1.

Example


section {

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

}

Transparent Background Color

The value transparent removes the background color and makes the element background clear.

Example


div {

    background-color:
    transparent;

}

Types of Background Color Values

Color Name

Uses predefined CSS color names like red, blue, and green.

HEX

Defines colors using hexadecimal color codes.

RGB

Creates colors using red, green, and blue values.

RGBA

Adds transparency support with alpha values.

Why Use CSS background-color?

🎨
Importance: Background colors improve webpage appearance, highlight important sections, and create better visual hierarchy.