Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<button> vs. <input type="button" />. Which to use?

When looking at most sites (including SO), most of them use:

<input type="button" /> 

instead of:

<button></button> 
  • What are the main differences between the two, if any?
  • Are there valid reasons to use one instead of the other?
  • Are there valid reasons to use combine them?
  • Does using <button> come with compatibility issues, seeing it is not very widely used?
like image 330
Aron Rotteveel Avatar asked Jan 22 '09 13:01

Aron Rotteveel


People also ask

What is the difference between an input with type of button and a button element?

The <button> tag permits phrasing content inside button element contents like text or images etc, along work with type functionality defined. But the input type=”button” attribute does not permit content.

What can I use instead of a button in HTML?

You use css and style a link <a> to look like a button.


2 Answers

Just as a side note, <button> will implicitly submit, which can cause problems if you want to use a button in a form without it submitting. Thus, another reason to use <input type="button"> (or <button type="button">)

Edit - more details

Without a type, button implicitly receives type of submit. It does not matter how many submit buttons or inputs there are in the form, any one of them which is explicitly or implicitly typed as submit, when clicked, will submit the form.

There are 3 supported types for a button

submit ||  "submits the form when clicked (default)" reset  ||  "resets the fields in the form when clicked" button ||  "clickable, but without any event handler until one is assigned" 
like image 33
Travis J Avatar answered Sep 28 '22 05:09

Travis J


  • Here's a page describing the differences (basically you can put html into a <button></button>)
  • And another page describing why people avoid <button></button> (Hint: IE6)

Another IE problem when using <button />:

And while we're talking about IE, it's got a couple of bugs related to the width of buttons. It'll mysteriously add extra padding when you're trying to add styles, meaning you have to add a tiny hack to get things under control.

like image 65
Tamas Czinege Avatar answered Sep 28 '22 03:09

Tamas Czinege