background color

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

CSS background-color Property

Example

Set the background-color of different elements:

body {
    background-color: yellow;
}

h1 {
    background-color: #00ff00;
}

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

Definition and Usage

The background-color property sets the background color of an element.

The background of an element is the total size of the element, including padding and border (but not the margin).

 

CSS Syntax

background-color: color|transparent|initial|inherit;

Property Values

Value Description  
color Specifies the background color. Look at CSS Color Values for a complete list of possible color values.  
transparent Specifies that the background color should be transparent. This is default  
initial Sets this property to its default value. Read about initial  
inherit Inherits this property from its parent element. Read about inherit  

More Examples

 

Example

Set the background-color of a part of the text:

span.highlight {
    background-color: yellow;
}