- background-color
- background-image
- background-repeat
- background-attachment
- background-position
Background Color
background-color property specifies the background color of an element.Example
body {
background-color: lightblue;}- a valid color name - like "red"
- a HEX value - like "#ff0000"
- an RGB value - like "rgb(255,0,0)"
Example
h1 {
background-color: green;}
div {
background-color: lightblue;}
p {
background-color: yellow;}Background Image
background-image property specifies an image to use as the background of an element.Example
body {
background-image: url("paper.gif");}Example
body {
background-image: url("bgdesert.jpg");}Background Image - Repeat Horizontally or Vertically
background-image property repeats an image both horizontally and vertically.Example
body {
background-image: url("gradient_bg.png");}background-repeat: repeat-x;), the background will look better:Example
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x;}background-repeat: repeat-y;Background Image - Set position and no-repeat
background-repeat property:Example
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;}background-position property:Example
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;}Background Image - Fixed position
background-attachment property:Example
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
background-attachment: fixed;}Background - Shorthand property
background:Example
body {
background: #ffffff url("img_tree.png") no-repeat right top;}background-colorbackground-imagebackground-repeatbackground-attachmentbackground-position
| Property | Description |
|---|---|
| background | Sets all the background properties in one declaration |
| background-attachment | Sets whether a background image is fixed or scrolls with the rest of the page |
| background-clip | Specifies the painting area of the background |
| background-color | Sets the background color of an element |
| background-image | Sets the background image for an element |
| background-origin | Specifies where the background image(s) is/are positioned |
| background-position | Sets the starting position of a background image |
| background-repeat | Sets how a background image will be repeated |
| background-size | Specifies the size of the background image(s) |