The CSS background properties are used to add backgrounds and background effects to the HTML page and HTML elements.
Background Color
The background-color property sets the background color of the entirety of an element.
div {
background-color: red;
}
Background Image
The background-image property sets one or more background images (with varying placement) for an element. The default placement is at the top-left corner.
div {
background-image: url("my-background.jpg");
}
Setting the Image Size, Repeat, and Position
The background-size property specifies the size of the background image. By default an image that doesn’t fill the element will repeat both vertically and horizontally starting from the top, left position. This can be changed.
div {
background-image: url("my-background.jpg");
background-size: 400px 200px;
background-repeat: no-repeat;
background-positon: right center;
}
Background Gradient
CSS lets you create smooth gradients between two or more specified colors.
- Linear Gradients (down/up/left/right/diagonally)
- Radial Gradients (radiating circular from their center)
- Conic Gradients (rotated around a center point)
Linear Gradient
div {
height: 100px;
background-color: red; /* default for browsers that don't support gradients */
background-image: linear-gradient(to right, red , blue);
}
Radial Gradient
div {
height: 100px;
background-color: red; /* default for browsers that don't support gradients */
background-image: radial-gradient(red, blue, green);
}
Conic Gradient
div {
height: 100px;
background-color: red; /* default for browsers that don't support gradients */
background-image: conic-gradient(red, yellow, blue, green);
}
Background Properties
- CSS – background Property
- CSS – background-attachment Property
- CSS – background-blend-mode Property
- CSS – background-clip Property
- CSS – background-color Property
- CSS – background-image Property
- CSS – background-origin Property
- CSS – background-position Property
- CSS – background-repeat Property
- CSS – background-size Property
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.
Why 1SMARTchicken?
See More →
Thanks for your support!
CSS Books
All are affiliate links. Thank you for your support!
CSS NOTES:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
Feedback
If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.