The background-color property is used to specify the background color of the element.
The background covers the total size of the element with padding and border but excluding margin.
CSS background-color property has a default value called transparent.
Contents
hide
Syntax
element {
background-color: color|transparent|initial|inherit;
}
Property Values
Value | Description |
---|---|
color | Specifies the background color. A color name can be given as: “green” or HEX value as “#5570f0” or RGB value as “rgb(25, 255, 2)”. |
transparent | Specifies that the background color should be transparent. This is default value. |
initial | Sets this property to its default value. |
inherit | Inherits this property value from its parent element. |
Example
<!DOCTYPE html>
<html>
<head>
<title>background-color property</title>
<style>
body {
text-align: center;
background-color: green;
}
h1 {
color: white;
background-color: blue;
}
h2 {
color: white;
background-color: black;
}
</style>
</head>
<body>
<h1>EyWiah.com</h1>
<h2>background-color: color_name;</h2>
</body>
</html>