HTML Form How to - Add background image to button








Question

We would like to know how to add background image to button.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
button:before {<!--from  w w  w  . j av  a  2 s.  co m-->
  content: "";
  display: inline-block;
  background-image: url(http://www.java2s.com/style/download.png);
  width: 10px;
  height: 10px;
  margin-right: 5px;
}
</style>
</head>
<body>
  <button>Edit</button>
</body>
</html>

The code above is rendered as follows: