Skip to content Skip to sidebar Skip to footer

Can A Form Tag Enclose A Body Tag?

Today I came accross some code which had a form tag before the body tag began. I mean, the form tag enclosed the body tag. Is this possible? If it is then where is it helpfull? <

Solution 1:

By looking up the W3C RecommendationsForm elements description, it clearly shows that you better not use that way.

You can use the Form element in:

Contexts in which this element can be used: Where flow content is expected.

Where Flow content is described as:

Most elements that are used in the body of documents and applications are categorized as flow content.

So by not following these recommendations, any HTML validators will also report you errors, since the forms opening closing tags are not found in side the body definition. Which is perfectly valid since:

Tag omission in text/html: Neither tag is omissible.

Solution 2:

Browser follows a forgiving approach but when I use it against the validator, it just throws up these errors. It is always good to follow the standards or browsers get confused.

Errors in W3C Validator

Solution 3:

Browsers are generally very forgiving when it comes to mistakes in the HTML structure, so it is possible and the form may still work, but it's still improperly coded HTML and it won't be helpful for anything in particular.

Solution 4:

Yes it is possible; the browser will mitigate it.

But it's unproper HTML syntax and I can't think of any cases where it might be helpful. The HTML body it just what it says on the label - a global page body container.

Post a Comment for "Can A Form Tag Enclose A Body Tag?"