backgroundImage Property (A, ADDRESS, ARTICLE, ...)

Switch View :
ScriptFree
background-image Attribute | backgroundImage Property

Gets or sets the background image of the object.

Syntax

CSS { background-image : sLocation }
Scripting [ sLocation = ] object.style.backgroundImage

Possible Values

sLocation String that specifies or receives one of the following values.
none
Default. Color of the next parent through which the background is visible.
url(sUrl)
Location of the background image(s), where sUrl is an absolute or relative URL.

The property is read/write for all objects except the following, for which it is read-only: currentStyle. The property has a default value of none. The Cascading Style Sheets (CSS) attribute is not inherited.

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.

Remarks

The URL identifies the image file. When setting a background image, you can set a background color to use when the image is unavailable. When the image is available, it overlays the background color.

This property can be set with other background properties by using the background composite property.

Microsoft Internet Explorer 3.0 supports the background-image attribute, but only when it's set through the background attribute.

 New for Windows Internet Explorer 9 In Internet Explorer 9, the background of a box can have multiple layers. The number of layers is determined by the number of comma-separated values in the background-image property. Each of the images is sized, positioned, and tiled according to the corresponding value in the other background properties ( background-attachment, background-clip, background-origin, background-position, background-repeat, and background-size). The first image in the list is the layer closest to the user, the next one is painted behind the first, and so on.

Examples

The following examples use the background-image attribute and the backgroundImage property to specify the background's image.

This example uses a call to an embedded (global) style sheet to show and hide the background image.


<style type="text/css">
.setUrl {
    background-image: url(sphere.jpg);
}
.loseUrl {
    background-image: url(none);
}
</style>
</head>

<body>

<span style="font-size: 14px" onmouseover="this.className='setUrl'" onmouseout="this.className='loseUrl'">
. . . </span>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/background-image.htm

This example uses inline scripting to show and hide the background image.


<span onmouseover="this.style.backgroundImage='url(sphere.jpeg)'">
. . . </span>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/backgroundImage.htm

Standards Information

This property is defined in Cascading Style Sheets (CSS), Level 1 (CSS1).

Applies To

A, ADDRESS, ARTICLE, ASIDE, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CSSStyleDeclaration, currentStyle, CUSTOM, DD, defaults, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FIGCAPTION, FIGURE, FOOTER, FORM, HEADER, HGROUP, hn, HTML, I, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MARK, MARQUEE, MENU, NAV, NOBR, OL, P, PLAINTEXT, PRE, runtimeStyle, S, SAMP, SECTION, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, CSSCurrentStyleDeclaration Constructor, CSSRuleStyleDeclaration Constructor, CSSStyleDeclaration Constructor