Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTomas Vesely
Front End Web Development Techdegree Graduate 22,327 PointsInput type button vs button element
Hi is there a reason (rule of thumb) when to use button as an element <button type=submit> and when to use <input type=submit>?
2 Answers
Robert Gulley
Front End Web Development Techdegree Student 10,722 PointsHi Tomas! -
The <input type="submit"> is still perfectly valid HTML, however the newer <button> element is now just the favored way to create buttons. Generally speaking, the <button> element is just easier to deal with.
Say, for example, you wanted to create a button that said "Click me!" on it. With the <button> element, you would simply have to code the following:
<button>Click me!</button>
/// Notice the Click me is between two <button> tags.
With an <input type="submit"> you would have to code the following:
<input type="submit" value="Click me!">
/// See how much more code this is?
There are additional advantages to using the button tag, such as when you are navigating the DOM in JavaScript, but ultimately it is your choice on which one you want to use.
Hope this helps!
Tomas Vesely
Front End Web Development Techdegree Graduate 22,327 PointsThank you Gulley Robert. It helps to clear things up for me.