CSS Background Color Property
Background Color Property is used to change the background color of an HTML Element, to make more effective.
Example 1 – CSS Background Color Property to Assign light green color to HTML p element.
<!DOCTYPE html>
<html>
<head>
<style>
p
{
background-color: lightgreen;
}
</style>
</head>
<body>
<p>Lorem ipsum lvinar mattialiquet enim tortor at auctor. Donec ultrices ium qua midnibh tortor id aliq ueted ris.</p>
</body>
</html>
In the above code, we define the background-color to an HTML Elements.
Caution:You can define background-color by color-names, HEX Code and RGB Values.
Example 2 – Use of Background Color Property with Hex code and RGB values
<!DOCTYPE html>
<html>
<head>
<style>
p
{
background-color: #b2ed9f;
}
body
{
background-color: rgb(28,139,151);
}
h1
{
background-color: #ecc272;
}
</style>
</head>
<body>
<h1>The Main Heading<h1>
<h2>The Sub-heading </h2>
<p>Lorem ipsum lvinar mattialiquet enim tortor at auctor. Donec ultrices ium qua midnibh tortor id aliq ueted ris.</p>
</body>
</html>
In the above code, we define the different background-colors to different HTML Elements.
Here, we define background-color to paragraph, <h1> and <h2> elements.

Note:By the use of background-color property, the look and feel of the web pages are appealing and easy to read the text.

April 4th, 2019
Nilesh Chaurasia
Posted in
Tags:
