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 trialJake Almendarez
Front End Web Development Techdegree Student 4,250 Pointsbutton element or input type submit?
i noticed in the last lesson about forms we saw how a button was made. in this lesson they use the input element to make a button. whats the difference and whats the preferred way to use each one?
1 Answer
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi Jake Almendarez,
This is a really good question, and the truth is the button and input element can often times be used interchangeably.
Probably the most glaring difference is that an input element can only be used within a form element, whereas a button element can just be any clickable button element. It does not have to be a form.
Another difference is that an input can have many different types (i.e. checkbox, radio, button, email, text, submit, etc.). So within a form an input offers more flexibility.
But say you were creating a web app (a platform game), and you found some cool music that would play throughout the game, but you wanted to allow your user to toggle the music on and off. In this case (out of an input element with the type button and an actual button element), you'd have no choice but to use a button.
Jake Almendarez
Front End Web Development Techdegree Student 4,250 PointsJake Almendarez
Front End Web Development Techdegree Student 4,250 Pointsthanks a lot @Brandon White . great example sir