There are three different types of elements that submit forms:
- <input type="image">
- <input type="submit">
- <button type="submit">
Logically, it would seem that you would want to use input type="image" if you wanted to display an image instead of a default button. However, using input type="image" causes the page to submit two extra variables for your x and y mouse click coordinates on the image as below. Unless you are specifically using this for advertising or some purpose that takes advantage of the coordinates, this is just unnecessary data that also causes the URL to become more complex.
Example URLs:
- type="submit"
- http://www.site.com/form.php?query=searchterm
- type="image"
- http://www.site.com/form.php?query=searchterm&x=0&y=0
Additionally, if you do not require additional information pertaining to the submit to be passed to the server (eg. you do not need to have two submits with different purposes), you can use a button element instead of an input. This also allows for simple hiding of the display text as outlined with the .hide-text class in this snippet (for if you wanted to put the text in the image instead).
This solution has been tested to work in:
- Microsoft Internet Explorer 6, 7, 8
- Mozilla Firefox 3.6
- Google Chrome 5
- Apple Safari 5
- Opera 10
This solution applies to a button-span pair defined as follows: <button type="submit" class="submit-button"><span class="hide-text">Submit the form</span></button> CSS === .submit-button { width: 30px; height: 15px; background: url(/your/button.png) no-repeat; /* Need full background declaration for IE 6 (instead of the shorter background-image) */ border: none; cursor: pointer; cursor: hand; /* For IE 5.0 and 5.5 */ vertical-align: top; } .hide-text { display: block width: 0; height: 0; overflow: hidden; }
Comments
Subscribe to comments
You need to login to post a comment.

text-indent:-9999; also works for block items instead of hiding it with a span.
text-indent:-9999; also works for block items instead of hiding it with a span.
Yeah, the text-indent off the left edge of the screen will work too, but I've encountered a problem on clicking these types of text-indent links where a dotted outline appears to go off the left side of the screen too. It looks like there is a way to fix this with some additional CSS / JavaScript (as per the link below), but I would rather place additional markup in the code instead of implementing a fix.
http://www.last-child.com/get-rid-of-the-dotted-lines-on-links-with-image-replacement/
please show me how to make searchform position vertical-middle within a DIV without the use of padding / margin
Sereal, is there any reason you're avoiding using margins? There's a number of solutions outlined in the post below, but the best use negative margins. I would reconsider trying to use margins - you should be able to make them work with any kind of design you have.
http://blog.themeforest.net/tutorials/vertical-centering-with-css/