vadnica-logo
Editor My Blog My Services About the Project Telegram O meni O meni

CSS Backgrounds: Colors, Images, Gradients and Positioning

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.

EXAMPLE
RESULT
Property Example Description
Basic Properties
backgroundbackground: #fff url(img.jpg) no-repeat center; Shorthand property for all background properties at once
background-colorbackground-color: #f0f0f0; Sets the background color of an element
background-imagebackground-image: url("image.jpg"); Sets an image as the background of an element
Position and Repeat
background-positionbackground-position: center top; Sets the starting position of the background image
background-repeatbackground-repeat: no-repeat; Repeats the image (repeat, no-repeat, repeat-x, repeat-y)
background-sizebackground-size: cover; Sets the size of the background image (cover, contain, px, %)
Attachment and Clipping
background-attachmentbackground-attachment: fixed; Sets whether the background image is scrollable or fixed
background-originbackground-origin: padding-box; Sets the origin position of the image (border-box, padding-box, content-box)
background-clipbackground-clip: border-box; Sets how far the background extends (border-box, padding-box, content-box)
Gradients
linear-gradientbackground: linear-gradient(to right, red, blue); Linear gradient (from one edge to another)
radial-gradientbackground: radial-gradient(circle, red, blue); Radial gradient (from center outward)
Advanced
background-blend-modebackground-blend-mode: multiply; Blends multiple backgrounds (color + image + gradient)
multiple backgroundsbackground: url(a.jpg), url(b.jpg); Multiple backgrounds at once (stacked on top of each other)