Reputation:
Are there still any benefits of using a <form>
element instead of let's say a <div>
element in the context of a single page application? The purpose of the <form>
element makes sense to me if the "form" submission isn't made with an ajax call (I'm talking about the more traditional way of submitting a form, with a input/button of type "submit" and the action attribute of the form element that describes the url to call), but otherwise I do not see it's utility (maybe for search engines?).
Upvotes: 16
Views: 5510
Reputation: 1542
No, you don't. The form tag, in terms of SPAs is largely archaic. However, it can be beneficial for accessibility issues.
As an alternative, you can specify roll="form".
<div role="form"
In general, there's no down side to use form. And, there are several good reasons to use the form tag, and only very few against. Treat it like a wrapping div tag around your input elements: also, you don't have to use the submit action.
Upvotes: 0
Reputation: 647
I think the answer is, no, if you're not going to "submit" a form, there's no need for the <form tag. Very often, our interactive controls are in places that would not be considered a "form" - checkboxes here, select menus there. I think most of them work just fine without a
Accessibility, I don't know anything about.
Upvotes: -1
Reputation: 13838
<form>
is clearer than <div>
.<form>
(since you used the word application, this may not be considered though).<div>
if you do care about accessibility.Upvotes: 8