HTML Image Submit Buttons (with Rollover)

Posted on Friday 1st Apr 2011 by James Bavington 8 Comments



In this week’s tutorial we take a look at how you can replace the standard HTML submit button with an image. Although you can style submit buttons with CSS, sometimes nothing can substitute using your own pixel-perfect image. In the tutorial we show you how simple it is to source an image and then change the Input Type accordingly.

Once the image is in place, we then take the tutorial one stage further by adding a little inline JavaScript to allow you to source a ‘Rollover’ or ‘Hover’ image. You can download the code used in the tutorial below:

HTML Image Submit Button

In the code below, we change the ‘type’ attribute from ‘text’ to ‘image’. In doing this, we then need to source the image with the ‘src’ attribute. As we are now using the ‘Image Type’, you have no need for the ‘value’ attribute.

<input name="submit" type="image" src="submit-up.gif" />

Adding the Rollover JavaScript

Next, you can choose to add the following, simple JavaScript to specify a Rollover State for your submit button.

<input name="submit" type="image" src="submit-up.gif" onmouseover="this.src='submit-over.gif'" onmouseout="this.src='submit-up.gif'" />

The above is a simple, compliant and effective method for customising your HTML Submit Buttons.

About James Bavington

Away from computers, James enjoys mountains, military history and has an insatiable appetite for film - particularly 90's classics.

See all of posts.

Add on James Bavington Google+

James Bavington's Tweet's

This entry was posted in Web Design Videos and tagged , . Bookmark the permalink.

8 Responses to HTML Image Submit Buttons (with Rollover)

  1. Aldo says:
    April 15, 2011 at 6:56 am

    Hi! thanks!
    What about if I have the submit script inside of a php tag?
    An error comes up. I think is because the single quotes.

    The error is: unexpected T_STRING

  2. James Bavington says:
    April 15, 2011 at 8:40 am

    Hi Aldo, try escaping the single quotation marks with backslashes like this:

    <?php echo '<input name="submit" type="image" src="submit-up.gif" onmouseover="this.src=\'submit-over.gif\'" onmouseout="this.src=\'submit-up.gif\'" /> ' ; ?>
  3. Tim says:
    June 6, 2011 at 6:06 pm

    Thanks James. Well presented, concise and effective. ATB, Tim

  4. Govinder says:
    November 15, 2011 at 8:49 pm

    Hi guys, great tutorial… but how can this be used for a reset button?

  5. Jonathan says:
    January 4, 2012 at 6:03 pm

    !!thanks you saved me a lot of time, its fast easy thanks again for sharing!!

  6. Pukkapixels says:
    January 24, 2012 at 10:34 pm

    Thanks – that’s so much easier than some of the other methods I’ve seen used! Great tutorial!

  7. Mike says:
    January 26, 2012 at 12:16 am

    can i add text on the button??

  8. James Bavington says:
    January 26, 2012 at 8:55 am

    Hi Mike, try our more recent tutorial, if you’re looking to have editable text /blog/videos/liquid-css-button.html

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>