CSS Background Property: Definition and Usage
CSS Background Property: Definition and Usage
The properties that can be set, are: background-color, background-image, background-position, background-
size, background-repeat, background-origin, background-clip, and background-attachment.
Property Values
Value Description
initial Sets this property to its default value. Read about initial
body {
background-color: yellow;
}
h1 {
background-color: #00ff00;
}
p {
background-color: rgb(255,0,255);
}
CSS Syntax
background-color: color|transparent|initial|inherit;
CSS background-image Property
Example
Set a background-image for the <body> element:
body {
background-image: url("paper.gif");
background-color: #cccccc;
}
Value Description
left top If you only specify one keyword, the other value will be "center"
left center
left bottom
right top
right center
right bottom
center top
center center
center bottom
x% y% The first value is the horizontal position and the second value is the
vertical. The top left corner is 0% 0%. The right bottom corner is
100% 100%. If you only specify one value, the other value will be
50%. . Default value is: 0% 0%
xpos ypos The first value is the horizontal position and the second value is the
vertical. The top left corner is 0 0. Units can be pixels (0px 0px) or
any other CSS units. If you only specify one value, the other value will
be 50%. You can mix % and positions
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit
Example
How to position a background-image:
body {
background-image: url('smiley.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
CSS Syntax
background-position: value;
Property Values
Value Description
scroll The background scrolls along with the element. This is default
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit