Skip to content Skip to sidebar Skip to footer

Is There A Good Reason That A Form Tag Should Not Exist In The Head Tag?

Is there a good reason that a form tag should not exist in the head tag? I was looking at this http://www.w3.org/html/wg/drafts/html/master/forms.html#the-form-element but I could

Solution 1:

If you look at http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2014 in a browser other than IE (which has a very strange bug here), you will see that your form element is not in fact inside the head element. When the parser sees the <form> tag, it automatically closes the <head> element, creates the <body> element and puts the <form> element and all subsequent elements inside that <body> element.

Because this behaviour is necessary for backward compatibility with existing web pages, the spec can't be changed to allow <form> elements in head, even if there were a good use case for doing so.

Solution 2:

HTML intended for display belongs in the <body> tag.

There are some browsers that will still display some tags that are put in the <head> tag, but that is not where it belongs and you are asking for interoperability problems if you put it there.

In the spec link that you referenced, it says that <form> tags go where flow content is expected. If you click on flow content, it refers to elements used in the body of documents. The body is what is in the <body> tag.

Post a Comment for "Is There A Good Reason That A Form Tag Should Not Exist In The Head Tag?"