/

HTML / CSS / JavaScript Tutorial

CSS Property: background

[this page | pdf | back links]

The CSS (CSS1 and CSS3) background property is a shorthand property combining (up to) 8 of the background properties.

 

Valid property values (other than inherit and initial) are defined by the elements of the shorthand. Shorthand elements (in the order in which they appear):

 

-        background-color

-        background-image

-        background-position

-        background-size

-        background-repeat

-        background-origin

-        background-clip

-        background-attachment

 

Default Value:

See individual properties

JavaScript syntax:

e.g. object.style.background="red url(mypicture.gif) top left no-repeat"

Inherited:

No

Animatable:

See individual properties

 

If one of the properties in the shorthand declaration is the background-size property then you need to use a “/” to separate it from the background-position property (the background-size property was added in CSS3), e.g.:

 

div {background: url(mypicture.gif) 10px 20px/40px 40px;}

 

More than one background-image can be specified. However, if you are using multiple background-image sources and also want a background-color then you need to put the background-color parameter last in the list.

 


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile