CSS background-color
Anonymous contributor
Published Jun 25, 2021Updated Nov 29, 2023
Contribute to Docs
The background-color property defines a color for the background of an HTML element.
Syntax
background-color: <value>;
Where <value> can be one of the following:
- Color keyword:
blue,transparent,rebeccapurple - Hexadecimal value:
#FF0000 - RGB value:
rgb(255, 0, 0) - RGBA value:
rgba(255, 0, 255, 0.3) - HSL value:
hsl(0, 100%, 50%) - HSLA value:
hsla(180, 80%, 100%, 0.8) - Special keyword values:
currentColor,transparent
Example 1
Set background color of the h1 element to be green:
h1 {background-color: green;}

Example 2
Set the background color of the h1 element to be transparent:
h1 {background-color: transparent;}

Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn CSS on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- In this CSS tutorial, you’ll learn how to add CSS to visually transform HTML into eye-catching sites.
- Beginner Friendly.6 hours