开发者

can you put things outside the outermost <html></html tags?

Somewhat of a follow-on question from here: 开发者_运维问答Is there a NO-OP tag in HTML?

Can you put stuff (tags) outside the main html tags? Will it work normally, will they be moved inside, will it confuse the renderer? In this case, the tags represent the start and end of an area to be replaced, which normally is some sub-section of the page, but theoretically should be able to include the entire page, which would necessitate the start and end tags to encompass the entire page.


It's invalid HTML to put tags outside the <html> tag, but it'll work just fine in just about every browser.

Depending on what tag you put outside the <html> tag, whether you've specified a doctype or not and perhaps some other factors, you may activate Quirks Mode which changes the way the browser parses and renders your page (this feature is designed to make older pages with invalid markup work properly)


Current browsers will "figure it out" and render what you probably intend to appear, but you'll be shooting yourself in the foot in many ways from SEO to web accessibility.


Everything should be inside the html tags, except for:

  • An xml tag can be used if you serve XHTML, however you should not have one as it makes IE ignore the doctype tag.
  • The doctype tag should be before the html tag.

You can of course place content after the html tag although it makes the document invalid. Browsers make their best to show everything that you throw at them, regardles of how badly formatted it is.

The biggest risk with this is that the behaviour is not defined in any standard, so browsers may react different to this. Some browsers might for example change rendering mode from Standads Compliance Mode to Quirks Mode, which can have bad consequences for your layout.


Can you put stuff (tags) outside the main html tags?

Yes, you can. Just try it.

Will it work normally, will they be moved inside, will it confuse the renderer?

I'm not really sure, but most browsers (or rendering engine) would still try to render it. The behavior is undefined though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜