Li Haoyi
Li Haoyi

Reputation: 15802

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.

Upvotes: 1

Views: 325

Answers (4)

Guffa
Guffa

Reputation: 700342

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.

Upvotes: 0

SeanCannon
SeanCannon

Reputation: 77966

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.

Upvotes: 1

LeleDumbo
LeleDumbo

Reputation: 9340

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.

Upvotes: 0

user47322
user47322

Reputation:

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)

Upvotes: 1

Related Questions