1

Every browser seems to treat pressing Enter as submitting a form. Is this behavior specified by HTML standards, or is it just commonly implemented by browsers?

Related though goes into much more detail about the exact behavior of buttons: Do all browser's treat enter (key 13) the same inside form?

The closest I've found, from https://www.w3.org/TR/html52/sec-forms.html#implicit-submission:

If the user agent supports letting the user submit a form implicitly (for example, on some platforms hitting the "enter" key while a text field is focused implicitly submits the form), then doing so for a form whose default button has a defined activation behavior must cause the user agent to run synthetic click activation steps on that default button.

This suggests that it's platform-dependent.

qwr
  • 9,525
  • 5
  • 58
  • 102

1 Answers1

0

In the html standard

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#implicit-submission

you'll find this:

4.10.21.2 Implicit submission

A form element's default button is the first submit button in tree order whose form owner is that form element.

If the user agent supports letting the user submit a form implicitly (for example, on some platforms hitting the "enter" key while a text control is focused implicitly submits the form), then doing so for a form, whose default button has activation behavior and is not disabled, must cause the user agent to fire a click event at that default button.

Essentially: the first submittable button (belonging to the form) in the DOM tree will be triggered on "Enter".

fsando
  • 71
  • 3