Question

Previously, when I've had a form with a single submit button on it, I've usually not put the type="submit" attribute in there. I've never observed this causing problems, and had believed that "submit" was the default type for a button and that I could rely on this behaviour.

However, w3schools and MDN disagree on whether I am right.

w3schools claims:

Tip: Always specify the type attribute for the <button> element. Different browsers may use different default types for the <button> element.

whereas MDN claims:

  • submit: ... This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.

Who is right and who is wrong - both according to spec, and in real browsers?

Was it helpful?

Solution

MDN has some spec links near the bottom of its article which confirm that what it says is correct: the default type of a button element is submit.

W3C HTML 4.01:

type = submit|button|reset [CI]
This attribute declares the type of the button. Possible values:

  • submit: Creates a submit button. This is the default value.
  • reset: Creates a reset button.
  • button: Creates a push button.

W3C HTML5:

The type attribute controls the behavior of the button when it is activated. It is an enumerated attribute. The following table lists the keywords and states for the attribute — the keywords in the left column map to the states in the cell in the second column on the same row as the keyword.

Keyword | State         | Brief description
--------+---------------+------------------
submit  | Submit Button | Submits the form.
reset   | Reset Button  | Resets the form.
button  | Button        | Does nothing. 

The missing value default is the Submit Button state.

What W3Schools is saying is that you should always specify the attribute to ensure as consistent behavior across browsers as possible. That doesn't imply that the attribute cannot legally be omitted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top