The CSS <background> properties allow us to set colors, images, and gradients for element backgrounds. With them, we can create anything from simple frames to complex visual effects.
The simplest background can be set with <background-color>. We can use any color in HEX, RGB, HSL, or by name.
In the following example, a light blue background color is given to a <div> element:
With <background-image> we can set an image, while with the <background> shorthand we can even define gradients. Image repetition and sizing can also be controlled.
With <background-repeat>, <background-size>, and <background-position> properties, we can precisely define how a background image appears. For example, cover fills the entire element, while contain keeps proportions.
In CSS we can define multiple background layers at once. For example, we can combine images and gradients in a single background declaration.
The background-attachment property controls whether the background remains fixed in the viewport (parallax effect) or moves with the content.
With the background shorthand property, we can define color, image, position, size, repeat, and attachment values all in one line.
Background properties can be combined in many creative ways. Some useful tips:
Please sign in to ask Lara about CSS background.
Select Language
Set theme
© 2025 ReadyTools. All rights reserved.