CSS background properties allow developers to control the background of elements, including colors, images, positions, and effects. This helps improve design and user experience on web pages.
Property | Description |
---|---|
background-color |
Sets the background color of an element. |
background-image |
Applies an image as the background. |
background-repeat |
Controls repetition of background images. |
background-position |
Defines the position of the background image. |
background-size |
Adjusts the size of the background image. |
background-attachment |
Specifies if the background is fixed or scrolls with the page. |
background |
A shorthand property for all background settings. |
background-color
)Applies a solid color as the background.
body {
background-color: lightblue;
}
💡 You can use color names, HEX, RGB, RGBA, HSL, or HSLA values.
background-image
)Sets an image as the background.
body {
background-image: url("background.jpg");
}
💡 Make sure the image path is correct to display it properly.
background-repeat
)Controls whether the image repeats across the page.