Style backgroundImage attribute

Definition and Usage

backgroundImage Set or return the background image of the element.

Tip:In addition to the background image, you should also specify the background color. If the image is not available, the background color will be used.

See also:

HTML Style:background attribute

CSS Tutorial:CSS Background

CSS3 Tutorial:CSS3 Background

CSS Reference Manual:background-image attribute

Instance

Example 1

Set the background image for the document:

document.body.style.backgroundImage = "url('img_tree.png')";

Try it yourself

Example 2

Set the specific <div> element's background image:

document.getElementById("myDiv").style.backgroundImage = "url('img_tree.png')";

Try it yourself

Example 3

Return the specific <div> element's background image:

alert(document.getElementById("myDiv").style.backgroundImage);

Try it yourself

Example 4

Return the background image of the document:

alert(document.body.style.backgroundImage);

Try it yourself

Syntax

Return backgroundImage attribute:

object.style.backgroundImage

Set backgroundImage attribute:

object.style.backgroundImage = "url('URL')|none|initial|inherit"

Attribute value

Value Description
url('URL) Location of the image file.
none No background image. Default.
initial Set this attribute to its default value. See initial.
inherit From its parent element, inherit this attribute. See inherit.

Technical details

Default value: none
Return value: karakara, wanda nufin girmu bakcin dake.
CSS version: CSS1

dabawon kawanci

backgroundImage ni yakiyawa CSS1 (1996) girmu.

Dabawon dake kawanci kawanci su kawanci kawanci:

Chrome Edge Firefox Safari Opera IE
Chrome Edge Firefox Safari Opera IE
Support Support Support Support Support Support