CSS background-color
The background-color
property in CSS is used to set the background color of an element. You can specify the color using various formats such as color names, RGB values, HSL values, and hexadecimal values. The background color will be applied to the entire element, including any content and padding inside it.
Syntax
selector {
background-color: value;
}
Where selector
is the element to apply the background color to, and value
is the color value you want to set.
Examples
<p style="background-color: lightblue; padding: 10px;">This is a lightblue background</p>
In the above example, we set the background color of the paragraph to lightblue
using the background-color
property.
<table>
<tr>
<td style="background-color: lightgreen;">Cell 1</td>
<td style="background-color: lightpink;">Cell 2</td>
</tr>
</table>
In the second example, we set the background color of the table cells to lightgreen
and lightpink
using the background-color
property. This demonstrates how you can apply background colors to different elements on a page.