CSS properties for backgrounds allow complete control over the appearance of HTML elements. With
them, we can set the background color, add images, determine their position, size, repetition method, and even create
advanced gradient transitions. The background property is a shorthand form for setting
all individual background properties at once in a single line of code.
| Property | Example | Description |
|---|---|---|
| Basic Properties | ||
background | background: #fff url(img.jpg) no-repeat center; |
Shorthand property for all background properties at once |
background-color | background-color: #f0f0f0; |
Sets the background color of an element |
background-image | background-image: url("image.jpg"); |
Sets an image as the background of an element |
| Position and Repeat | ||
background-position | background-position: center top; |
Sets the starting position of the background image |
background-repeat | background-repeat: no-repeat; |
Repeats the image (repeat, no-repeat, repeat-x, repeat-y) |
background-size | background-size: cover; |
Sets the size of the background image (cover, contain, px, %) |
| Attachment and Clipping | ||
background-attachment | background-attachment: fixed; |
Sets whether the background image is scrollable or fixed |
background-origin | background-origin: padding-box; |
Sets the origin position of the image (border-box, padding-box, content-box) |
background-clip | background-clip: border-box; |
Sets how far the background extends (border-box, padding-box, content-box) |
| Gradients | ||
linear-gradient | background: linear-gradient(to right, red, blue); |
Linear gradient (from one edge to another) |
radial-gradient | background: radial-gradient(circle, red, blue); |
Radial gradient (from center outward) |
| Advanced | ||
background-blend-mode | background-blend-mode: multiply; |
Blends multiple backgrounds (color + image + gradient) |
multiple backgrounds | background: url(a.jpg), url(b.jpg); |
Multiple backgrounds at once (stacked on top of each other) |