Depends on what you are considering as "HTML code validation". If it is the result of HTML validation tools that can be found on the Internet, including W3C, yes, there is a possibility that your file may become invalid. This matters? No. Because if you consider the W3C definitions and specifications, which is a consortium that defines web standards, your validation file will remain valid.
In the documentation itself in MDN you can check:
Allowed parent elements Any element that accepts phrased content.
That is, any element that accepts wording content may contain elements input
, button
, select
, etc. Note that at no time is it described that it must be within a form
element.
The same W3C specification comes from this same stretch:
Contexts in which this element can be used : Where phrasing content is expected.
Is it considered bad practice to use them outside form
? Not necessarily. The correct question to ask is: does it make sense in my application to use them like this? If the answer is yes, you can use them without problems. It is even common for developers to use other elements in a wrong way with the 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 button
itself, even outside a form or to send information to the server.