HTML CSS SQL Meta tag Generator ScrollBar design Generator Encode Decode images

CSS Basics

Introduction Syntax Selectors Attribute Selectors Specificity Combinators !important Comments Colors

CSS Need to Know

Box Model Pseudo-class Pseudo-element Inline-block Math Functions Max and Min Opacity Outline Overflow Z-index Float

Most used

Align Backgrounds Borders Text Units Padding Margins Position Tables Display Fonts Lists Height and Width

CSS Reference

CSS Properties reference CSS Pseudo-Classes reference CSS Pseudo-Elements reference CSS Selector reference

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>
Result:

This is a lightblue background

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>
Result:
Cell 1 Cell 2

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.

<i>Tower of Pisa</i>