home / software / tips and tricks / How to set a background-image for an html element?

How to set a background-image for an html element?

Updated:  07/08/2010 10:07 AM
Author:  Shiju Mathews

Status:    Resolved.


add a style to the element as:



Make sure the image path is valid and accessible.

The background-image property sets the background image for an element.

The background of an element is the total size of the element, including padding and border (but not the margin).

By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.

Also this can be done using JavaScript.This method can be used to change the image on runtime.
syntax: object.style.backgroundImage="url(stars.gif)"
Tags: How to set a background-image for an html element?
Updated on: April 2024