The button element

Tuesday 19th June 2007 04:21 PM

TAGS: html, button
This is quite a cool article I saw a while back on the forgotten <button> element, which is something that I didn't know about.

Most html writers will be familiar with:

<input type="submit" name="test" value="Click Me" />

Suppose though, that you want to make a clickable image. You can use some CSS markup, but instead with the button element, you can also do something like...

<button type="submit" name="test" value="Click Me">
  <img src="images/click_me.jpg" alt="Click Me" />
</button>


I'm not quite sure on how the best way to deal with screen readers or text-based browsers is, but the alt tag should work fine for that. If not, perhaps a hidden span inside the button element would work better.

Comments on this article:


#1 Jeroen Mulder says:

Tuesday 19th June 2007 06:10 PM

I actually always use the negative text-indent image replacement with the button element to create custom looking buttons. Good for accessibility.

This also allows me to keep my presentation in my stylesheet and not need to include an image in the markup (either through inline content in a button or an input of type 'image')

The added benefit is that in most browsers no native OS styling is applied to the button element. For example, it works perfectly in Safari.

#2 Gavin says:

Tuesday 19th June 2007 06:20 PM

All good points Jeroen! Thanks.

I do agree perhaps having an image inline isn't the best option.


Add Comment:


Make a Comment

*Nb, all comments are moderated to prevent spam or inappropriate content.








netforge logo
netforge provides high quality and friendly website design services to business. We're Australian based and reliable... (find out more).