It depends on what you are considering as "HTML code validation". If it is the result of HTML validation tools that can be found over the internet, including W3C, yes, there is a possibility that your file will become invalid. Does it matter? No. Because if you consider as validation the definitions and specifications of W3C, which is a consortium that defines the web standards, your HTML file will remain valid.
In the documentation itself on the MDN it is possible to check:
Permitted parent elements Any element that accepts phrasing content.
That is, any element that accepts phrasing content may contain elements input
, button
, select
, etc. Note that at no time is it described that you must be inside an element form
.
The very specification of the W3C behind that same stretch:
Contexts in which this element can be used: Where phrasing content is expected.
It is considered bad practice to use them outside the form
? Not necessarily. The correct question to ask is: does it make sense in my application that I use them like this? If the answer is yes, you can use them without problems. It is even common for developers to mistakenly use other elements for fear of using such "form" elements. A classic example is to use an anchor element, a
, to open a modal window; semantically it would be better to use the modal window itself button
, even outside of a form or to send information to the server.
If you validate the pages in most HTML validators, there will surely be element errors without form, or form without elements. In matters of SEO I believe I have no problem, in matters of programming I think also not. Maybe you would if you wanted to load these values between pages.
– cHida