CSS: Backgrounds

Learn how to style the background of elements using CSS.

Background Properties

CSS provides several properties to style backgrounds:

Example: Background Styling

/* Example */
div {
    background-color: #f0f0f0;
    background-image: url('background.jpg');
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}
        

This example applies a background image with specific styling to a div element.

Practice

Try experimenting with background properties:

Continue Learning

Quick Check

Which background-size value scales the image to completely cover the container?