HTML Form How to - Add background image for input type="button"








Question

We would like to know how to add background image for input type="button".

Answer


<html>
    <head>
        <style type="text/css">
.button<!--from   w  w  w . j  av a 2 s  .  com-->
{
   background: url(http://www.java2s.com/style/download.png) no-repeat;
   cursor:pointer;
   border: none;
}
        </style>
    </head>
    <body>
        <input type="button" name="button" value="Search" onclick="showUser()" class="button"/>
        <input type="image" name="button" value="Search" onclick="showUser()" class="button"/>
        <input type="submit" name="button" value="Search" onclick="showUser()" class="button"/>
    </body>
</html>

The code above is rendered as follows: