With modern javascript (and js framework too!) and different ways to do a sync/async actions (POST, GET etc,..) I am still wondering why would one still want to use form element?
Is it due to code semantics and actually "specifying" an area from which something is submitted?
Is it because form acts as a helper that "collects" (poorly I would say) data?
All of the above can be easily done in javascript, so I cannot think of any other reason for using form for submitting data?
Semantics and accessibility # If something is a form, use a form element. This helps assistive devices like screen readers better understand the content of the page and give the person using them more meaningful information.
If all your input field is doing is providing a UI (user interface) hook for interactions, then you can put the input fields into the HTML without including a FORM tag.
An HTML form is used to collect user input. The user input is most often sent to a server for processing.
Form tags are still necessary if you want to be able to submit the form without AJAX (which may be useful in the early stages of development).
Writing unobtrusive JavaScript that works using progressive enhacement continues to be best practise because there are plenty of circumstances where JavaScript fails.
Aside from that, just because you can do something with JavaScript doesn't mean you should do something with JavaScript. Often a regular form submission will give all the desired effects with less work.
And on top of that, a form is a useful element to collect data with even if you do use JavaScript. For example, you can use a form element to populate a FormData
element.
Forms provide semantic data to group form controls, this is heavily used by screen readers.
As mentioned in comments, some password managers use them to identify grouped login form controls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With