The background-image property sets one or more images as background for an element. It takes as value a list of image URLs or gradients (which are images to CSS). The images are stacked from the last in the list which appears behind to the first one in the front. The background-color appears behind all the background images.
background-image: url('imageUrl'); background-image: linear-gradient(to bottom, LightGreen, green); background-image: url('imageFrontUrl'), url('imageMidUrl'), url('imageBehindUrl'); /* Multiple images, last one appears behind */
Image URLs must be quoted. CSS gradients are created using a gradient function: linear-gradient, radial-gradient, repeating-linear-gradient, repeating-radial-gradient. Comma-separate images and/or gradients to have multiple layers.
Browser Support: Full for images. Almost full for gradients. IE9 and bellow don't support them. See the caniuse CSS gradients compatibility table for details.
Multiple Background Images
Use a comma-separated list of URLs for multiple background images. The last image from the list will appear behind and the first one in the front.
Gradients are images for CSS. To create a gradient background, simply use one of the gradient functions as value for the background-image property or the background shorthand. These functions are linear-gradient, radial-gradient (circular shapes), repeating-linear-gradient and repeating-radial-gradient (exactly! they repeat the gradient). The first parameter sets the starting position (end position for the standard, not yet supported), and then comes a list of color stops, two at least. See the CSS gradients page for more information. Here's for a simple gradient:
Several gradients or a combination of grandients and images are allowed as well.
The background area
The background paints the content, padding and border areas by default. It's good practice to specify a background color that will show up before the image loads or in case it's not found.
The background-clip property allows customizing the painting area of the background color and image.
Stop from Repeating with background-repeat
Sometimes you want the background image to appear only once, or to be repeated horizontally or vertically only. The background-clip property allows it. A value of no-repeat will render the image once. repeat-x will produce a single horizontal row, and repeat-y does the same vertically. The case of gradients is different. They are always stretched to fit. To repeat a gradient use one of the repeating gradient functions.
Note that there's no way to repeat the background image a fixed number of times, twice for example (other than setting the container to be twice as wide/tall as the image).
Centering the Background Image
The background-position property allows centering the background image vertically and/or horizontally. It sets the starting position of the background image, which is repeated by default. To center a single instance of the background image set background-repeat to no-repeat.
the first value of background-position gives the horizontal alignment: left, right or center. The second one gives the vertical alignment: top, centeror bottom.