Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
Should I use a <form> or just a <div> to create a form?

I am using React JS with Apollo client, when I want to create like a registration form for example, I usually create a div which contains some input fields and a button, the button is not of type "submit" it is just a regular button with an "onClick()" event that runs the registration function ... it does the job and I like the way the registration logic runs without passing any data through the URL as well as it doesn't need to refresh the page after each registration approach.

So the question is which way is better ?

  1. Using a form tag to do form things
  2. Using a div instead

NOTE: I know that there is some packages that can handle these situations like "Formik" for example ... but I like to code everything my self.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In my opinion, it's always better to keep using semantic HTML tag e.g <form> for form.

There are some advantages using <form> from what I've known so far:

  1. Support CSS pseudoclass :invalid and :valid which may be handy
  2. Better accessibility

Note: Using the element will automatically communicate a section of content as a form landmark, if it is provided an accessible name. Developers should always prefer using the correct semantic HTML element over using ARIA.

Source: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/form_role#description

For CSS pseudoclass demo, you could check my Stackblitz

about 4 years ago · Juan Pablo Isaza Report

0

I would recommend using <form> and make your <button> of type="submit".

Instead of adding an EventHandler to the button on onClick, I would bind it to the onSubmit event of the form.

With event.preventDefault() you stop the submission of the form and you can handle your registration logic there.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!