3 ms·
here is an edge case: the <head>-tag might be optional, but HTML elements do have a different behavior when placed in the <head> section or the <body> section.
by franze 10y ago
here is an edge case: the <head>-tag might be optional, but HTML elements do have a different behavior when placed in the <head> section or the <body> section.
namely, the always beloved <noscript> tag https://developer.mozilla.org/en/docs/Web/HTML/Element/noscript https://developer.mozilla.org/en/docs/Web/HTML/Element/noscr...
which is a flow content element in the body section
but if used in the <head> it might include links, style and meta-tags and then it should not be treated as content element.
as the <head> element therefore changes the behavior of its child-elements, does this make it non optional?
p.s.: i think DOMParser.parseFromString() in Chrome gets this <noscript> behaviour wrong in some cases (closes the <head>-section as it treats the <noscript>-tag as content-element, even though it is in the <head> with just links & style children, so it shoudn't close the <head>...)
- franze 10y agoreplying to myself like a pro: after reading the spec https://www.w3.org/TR/html5/scripting-1.html#the-noscript-element https://www.w3.org/TR/html5/scripting-1.html#the-noscript-el..., the <noscript> element is even trickier, it has at least 4 parsing modes: in the head with scripting disabled (no text, only link, style, meta) in the head, with scripting enabled (can include text (like whitespaces) but parsed elements must result in link,style,meta DOM only) in the body with scripting disabled (text, but no other noscript) in the body with scripting enabled (text, but no other noscript and script tags) so basically <html><noscript><link href="e.css"></noscript><title>hi</title><h1>ho</h1> would be find, as the <head> would close just before the <h1> (in scripting enabled and disabled case) but: <html><noscript> <link href="e.css"></noscript><title>hi</title><h1>ho</h1> would close the <head> in a scripting disabled case just before the <noscript>-tag and closes the <head> just before the <h1> in a scripting enabled case. this would explain the DOMParser.parseFromString() behaviour, as it's a scripting disabled case....
- zcorpan 10y agohttp://software.hixie.ch/utilities/js/live-dom-viewer/saved/4486 http://software.hixie.ch/utilities/js/live-dom-viewer/saved/... In Chrome Canary 55.0.2866.0 the noscript element contains a text node and a link element. This matches the spec as far as I can tell; whitespace is allowed in noscript in head.