HTML Form How to - Use an image for a button instead of standard input type button








Question

We would like to know how to use an image for a button instead of standard input type button.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.button:hover {<!--  ww  w  .j  av a  2s .c  om-->
  cursor: pointer;
}
</style>
</head>
<body>
  <input type="button" onclick="alert('A message here');" value="Button" />
  <img class="button" src="http://www.java2s.com/style/download.png" width="100" height="100"
    onclick="alert('A message here');">
</body>
</html>

The code above is rendered as follows: