CSS CSS Selectors Selectors - Beyond the Basics Child, Adjacent, and General Sibling Combinators

Jake Almendarez
seal-mask
.a{fill-rule:evenodd;}techdegree
Jake Almendarez
Front End Web Development Techdegree Student 4,249 Points

button 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
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi 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.