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?).
- Semantically, using
<form>
is clearer than<div>
. - If you still want your form to work without JavaScript, you'd better choose
<form>
(since you used the word application, this may not be considered though). - More importantly, it'll be really painful of using
<div>
if you do care about accessibility.
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.
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.
© 2022 - 2025 — McMap. All rights reserved.
serialize()
– Checkroom