CSS Backgrounds
CSS Backgrounds
CSS Backgrounds
Dark mode
Dark code
HTML
CSS Backgrounds
‹ Previous Next ›
background-color
background-image
background-repeat
background-attachment
background-position
background (shorthand property)
CSS background-color
The background-color property specifies the
background color of an element.
Example
The background color of a page is set like this:
body {
background-color: lightblue;
}
Try it Yourself »
Other Elements
You can set the background color for any HTML
elements:
Example
Here, the <h1>, <p>, and <div> elements will
have different background colors:
h1 {
background-color: green;
}
div {
background-color: lightblue;
}
p {
background-color: yellow;
}
Try it Yourself »
Opacity / Transparency
The opacity property specifies the
opacity/transparency of an element. It can take a
value from 0.0 - 1.0. The lower value, the more
transparent:
opacity 1
opacity 0.6
opacity 0.3
opacity 0.1
Example
div {
background-color: green;
opacity: 0.3;
}
Try it Yourself »
100% opacity
60% opacity
30% opacity
10% opacity
Example
div {
background: rgba(0, 128, 0, 0.3) /*
Green background with 30% opacity */
}
Try it Yourself »
Property Description
‹ Previous Next ›
NEW
We just launched
W3Schools videos
Explore now
COLOR PICKER
Get certified
by completing
a CSS
course today!
school
w3 s
2
CE
02
TI 2
R
FI
ED .
Get started
CODE GAME
Play Game
Report Error
Spaces
Pro
Buy Certificate
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples
Get Certified
HTML Certificate
CSS Certificate
JavaScript Certificate
Front End Certificate
SQL Certificate
Python Certificate
PHP Certificate
jQuery Certificate
Java Certificate
C++ Certificate
C# Certificate
XML Certificate
FORUM | ABOUT