You are here: Reference > JavaScript > client-side > style handling > properties > backgroundImage

backgroundImage style property

Browser support:
Specifies or returns the image to use as the background of the object.


You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: background-image

Possible values:

The type of this property is string.
 One of the following values: 
Where URI specifies the location of the image file.
Takes the value of this property from the computed style of the parent element.
Default. Specifies that the current element does not have a background image.
Default: none.

Example HTML code 1:

This example illustrates the use of the background-image property:
        .example {
            background-image: url("bg.jpg");
            background-repeat: repeat;
            width: 300px;
            height: 200px;
            overflow: scroll;
    <div class="example">
        Some content ..... <br /> ..... <br /> ..... <br />
        Some content ..... <br /> ..... <br /> ..... <br />
        Some content ..... <br /> ..... <br /> ..... <br />
        Some content ..... <br /> ..... <br /> ..... <br />
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the backgroundImage property in JavaScript:
    <script type="text/javascript">
        function ChangeImg () {
            div = document.getElementById ("myDiv");
            input = document.getElementById ("myInput");
            alert (input.value);

   = "url('" + input.value + "')";
    <div id="myDiv">Change the background-image</div>

    Please set a .gif, .png, .jpg or a .bmp file to see the effect.
    <input id="myInput" type="file" />
    <button onclick="ChangeImg ()">Change image</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content