Input elements outside the form tag

4

I would like to know if it is considered a bad entry attributes outside the form tag.

  

In w3schools

The <form> tag is used to create an HTML form for user input. The <form> element may contain one or more of the following form elements:

<input>
<textarea>
<button>
<select>
<option>
<optgroup>
<fieldset>
<label>
  

At MDN

The <form> HTML element represents a section of a document that contains interactive controls that allow the user to submit information to a particular web server.

It is correct to use such attributes without HTTP calls ?, does this affect anything related to HTML code validation?

    
asked by anonymous 11.09.2017 / 19:31

2 answers

2

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.

    
12.09.2017 / 00:04
1

It is not considered a bad practice, as long as it manages a good interface and makes sense.

For example a reset button, or clear a feed, may be out of shape.

More information: link

    
11.09.2017 / 22:12