Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<head>
<style>
div {
  width: 400px;
  height: 400px;
  border: 1px solid black;
}
</style>
</head>
<body>
<h1>HTML Style Object</h1>
<h2>The backgroundImage Property</h2>
<div id="myDiv">This is a myDiv.</div>
<br>
<button type="button" onclick="myFunction()">Set the background image of myDiv</button>
<script>
function myFunction() {
  document.getElementById("myDiv").style.backgroundImage = "url('img_tree.png')";
}
</script>
</body>
</html>