CSS background-color Property

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

Description

The background-color property determines the background color of an element. The background of the element is the total size of the element, including the values ​​of padding (inner margins of the element) and border (borders), but not including the value of the margin property (outer margins of the element). The color value is allowed to be specified both in the hexadecimal system and in RGB, RGBA, HSL, HSLA systems, as well as using predefined colors.

Initial value
transparent
Applies to
All elements
Inherited
No
Computed value
The computed color
Animatable
Yes
JavaScript syntax
object.style.backgroundColor

Interactive Demo

Syntax

background-color: <color> 

Values

  • <color>Accepts a single color as its value, which can be a keyword, hex, RGB, RGBa, HSL or HSLa color value.
  • transparentThe default value; you will be able to see the elements behind the element in question showing through it.
  • inherit

Example

<h1>Lorem ipsum dolor sit amet</h1> 
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.</p>
body { 
   background-color: #3366CC;
} 
h1 { 
   background-color: RGB(249, 201, 16); 
} 
p { 
   background-color: maroon;
   color: white;  
}

Browser Support

The following table will show you the current browser support for the CSS background-color property.

Desktop
Edge Chrome Firefox Opera Safari
12113.51
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
184141137

Last updated by CSSPortal on: 1st January 2024