Input submit Vs Button submit tags? 🤷🏼‍♀️ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Input submit Vs Button submit tags? 🤷🏼‍♀️

Usually when I see some php tutorials or github repositories they use the input tag with the "submit" type instead a button. Why they use it? Which one is better? And why? (When I change the input tag for a button I get the same result so that's where my doubt has borned)

11th Apr 2021, 6:20 PM
Ariadne Rangel
Ariadne Rangel - avatar
3 Answers
+ 1
<input type="button" /> buttons will not submit a form - they don't do anything by default. They're generally used in conjunction with JavaScript as part of an AJAX application. <input type="submit"> buttons will submit the form they are in when the user clicks on them, unless you specify otherwise with JavaScript.
11th Apr 2021, 8:45 PM
Jamal Saied
Jamal Saied - avatar
Jamal I'm sorry, maybe I didn't explain it well. I mean the difference between <button type="submit"> and <input type="submit"> 💁🏼‍♀️
11th Apr 2021, 9:02 PM
Ariadne Rangel
Ariadne Rangel - avatar
<button> allows content within, <input> does not. <button> by default acts as submitter when placed within a <form>. Adding attribute `type = "button"` changes the default behaviour.
12th Apr 2021, 3:59 AM