CSS Background Property


The background-color property specifies the background color of an element.

The background color of a page is defined in the body selector:

Syntax

background: color position/size repeat origin clip attachment image|initial|inherit;

Example

body {
    background-color: #338844;
     }

Note: If one of the properties in the shorthand declaration is the background-size property, you must use a / (slash) to separate it from the background-position property, e.g. background:url(run.png) 10px 20px/50px 50px; will result in a background image, positioned 10 pixels from the left, 20 pixels from the top, and the size of the image will be 50 pixels wide and 50 pixels high.

Set following background properties of an element:

ValueDescription
background-image property is used to set the background image of an element.
background-color property is used to set the background color of an element.
background-repeat property is used to control the repetition of an image in the background.
background-position property is used to control the position of an image in the background.
background-attachment property is used to control the scrolling of an image in the background.
background property is used as shorthand to specify a number of other background properties.

Share this article on