The background of an element, beside a color, may be an image as well. That is achieved with the property called background-image.

When setting up an image, it is always a good practice to assign a color as well in case if the image cannot be rendered. When the image is rendered properly the background color, if set, will be visible only in the transparent parts of the image.

The background-image property contains following information:

  1. value: <uri>, none or inherit;
  2. initial: none;
  3. applies to: all elements;
  4. inherited: no;
  5. percentages: N/A;
  6. media: visual;
  7. computed value: absolute URI or none.

If the image has intrinsic dimensions (width, height) specified as percentages, its dimensions will be relative to coordinates defined with the background-position property. If the image has any of the intrinsic dimensions and the ratio, its dimensions will be calculated from these intrinsic values; on the other hand if the image has one of the intrinsic dimensions but not the ratio its dimension will be the size of the coordinates defined by the background-position property. If the image has no intrinsic dimensions but has the ratio its dimensions are assumed to be the largest dimensions at that ratio as long as they don't exceed the dimensions given within the coordinates specified with the background-position property. Finally, if the image has no intrinsic dimensions, nor the ratio, its dimensions are assumed to be those given within the coordinates specified with the background-position property.

Example

CSS background-image property example:

 

›› go to examples ››