As the name suggests, the background-color is a property in CSS and is used to set the background color of an HTML element.
Let us understand with the below example.
<html> <body> <p style = "background-color:blue">This is the first paragraph</p> <p style = "background-color:red">This is the second paragraph</p> </body> </html>
To set the background color for the paragraph, we have used the background-color property of the style attribute.
<p style = "background-color:blue">This is the first paragraph</p>
The background-color property is not just restricted to the <p> element. But we can use it any other elements like <span> or <div>.
<html> <body> <div style = "background-color:blue">This is the first div element</div> </body> </html>
To set the background color for the <div> element, we have used the background-color property of the style attribute.
<div style = "background-color:blue">This is the first div element</div>
Also with the background-color property, we can use the opacity property to set the opacity of background color.
<html> <body> <div style = "background-color:red">This is the first div element using red color</div> <div style = "background-color:red;opacity:0.6">This is the second div element using red color and opacity</div> </body> </html>
So, in the above example, we have used two <div> elements.
The first <div> element uses the background color red with no opacity.
<div style = "background-color:red">This is the first div element using red color</div>
And the second <div> element uses the the background color red with opacity 0.6.
And if you see the above output, you can see a slight blur effect for the second <div> element due to the opacity property.