Creating Form element

why is it necessary to use <form></form> syntax ? when we can directly type <input type="text".

1 Like

A form element is necessary to submit the form to the server. If you are just trying to have markup and access the markup via JavaScript, then you don’t technically need a form. However, if you want to submit the form to a server via the traditional way, you need a form element.

<!-- you can't do anything with this really -->
<input type="text" name="firstname"/>
<input type="email" name="email"/>

<!-- But you can submit these values to a webserver -->
<form action="/server_route.php">
  <input type="text" name="firstname"/>
  <input type="email" name="email"/>
</form>
3 Likes