Embracing buttons

In his RailsConf UJS presentation, Dan was quite clear about the appropriate use of links and buttons – only use links for GETting resources – not for POST, DELETE, PUT or any other HTTP verb that implies some kind of destructive behaviour.

The problem with this however is that it requires you to litter your page with ugly forms and input buttons. However, there is a HTML element that can come to your rescue; the button element.

Unlike submit buttons (created with the input element) they are much more flexible in terms of what you can put in them and how you can style them. For instance, did you know you could use semantic markup inside the button?


<button type="submit">Click me <strong>now!</strong</button>

For more information on using the button element, check out Aaron Gustafson’s excellent article on Digital Web Magazine entitled Push my button.

Return to home page

4 Comments on this article

1. Comment by Bolo on 17 Oct 2006 at 03:10

So if i understand correctly we can user button element with POST and Co. ?

2. Comment by Luke Redpath on 17 Oct 2006 at 08:10

Bolo – thats right, though you usually need a form too (unless you are using a JS/AJAX post).

3. Comment by Bolo on 17 Oct 2006 at 10:10

Yesterday, i readed the article. It seems that this solution don’t work correctly with IE.
Or maybe i don’t undrestand all :p

4. Comment by Bolo on 20 Oct 2006 at 11:10

Do u test this solution with form_remote_fo ‘cause for me i can get back the value (of button). It’s always empty.

Return to home page

Have your say