The background-color
property is used to set the background color of an element. It sets a background color using a <color>
value.
The element can also have one or multiple background images set using background-image
property.
The color set with the background-color
property is drawn behind any background images. If one background image is set and the image turns out invalid, then the background color will be visible.
The background color is clipped according to the background-clip
value associated with the bottom-most background image. Check the background-clip
entry for details on how to clip a background color.
Sometimes, even if a valid background image is set, the color can still show through if the background image is not fully opaque, like if you’re using an image with fully-transparent areas (an image with an alpha channel).
Trivia & Notes
When using a background image on an element that has some text, you should make sure that the color of the text is not too similar to, or the same as the background color of that element; otherwise the text would be unreadable if the image could not be shown for some reason.
Official Syntax
-
Syntax:
background-color: <color>
- Initial: transparent
- Applies To: all elements
- Animatable: yes
Values
Examples
The following sets the background color of all h1
elements to black.
h1 { background-color: #000; color: white; }
The following sets the background color of all elements of class module
.
.module { background-color: hsla(250, 30%, 50%, 0.9); }
Browser Support
The background-color
property works in all major browsers: Chrome, Firefox, Safari, IE, Opera, and on Android and iOS.