HTML Form How to - Add background to button








Question

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

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
button:before {<!--from   w w w.  j a  v  a 2  s . co  m-->
  content: ' ';
  width: 50px;
  height: 50px;
  background: url(http://www.java2s.com/style/download.png);
  display: inline-block;
  vertical-align: middle;
}
</style>
</head>
<body>
  <button>Test</button>
</body>
</html>

The code above is rendered as follows: