3 ms·
> The only other style that is special is "style" itself, which has to include an escape character to avoid being taken literally. style::before {content:'
by kccqzy 7y ago
> The only other style that is special is "style" itself, which has to include an escape character to avoid being taken literally.
style::before {content:'<style>'}
style::after {content:'<\/style>'}
I don't think it's a bug. After all, browsers have very lenient parsers and if there's a syntax error (unterminated quote) in the style it shouldn't affect the rest of the HTML. The same goes for JavaScript: you probably still can't use the string literal '</script>' within an inline script.
- sadjad 7y ago> you probably still can't use the string literal '</script>' within an inline script. You're right: https://jsfiddle.net/pLo9bdhs https://jsfiddle.net/pLo9bdhs
- deleted 7y ago[deleted]
- pluma 7y agoThink about the failure cases for `</script>` and `</style>` and it's obvious why the spec defines them that way. If CSS and JS syntax were to decide when the end tags can appear, some malformed CSS or JS would break the end tag and cause the entire rest of the document to vanish as the browser wouldn't recognise it as HTML.
- throwaway66666 7y agoAnd image tags do not have pseudo selectors/elements.
- tazard 7y agoWith the experience of Chrome, neither do input tags. In fact I believe only 'container' elements are supposed to.
- missblit 7y agoYep not a bug. Or at least if it's a bug, it's a bug in the HTML spec. But really I think it's pretty reasonable behavior. Short answer is standard says to parse the contents of <style> elements as text. Long answer is style start tag triggers [1] the generic raw text element parsing algorithm [2] which switches the parsers insertion mode to "text" [3] which only exits once an end tag is seen. Given that the generic raw text element parsing algorithm switched the tokenizer to RAWTEXT state [4] it will only output an end tag token from the RAWTEXT end tag name state [5] for an appropriate end tag token [6] which by definition will be "</style>" [1] https://html.spec.whatwg.org/#parsing-main-inhead https://html.spec.whatwg.org/#parsing-main-inhead [2] https://html.spec.whatwg.org/#generic-raw-text-element-parsing-algorithm https://html.spec.whatwg.org/#generic-raw-text-element-parsi... [3] https://html.spec.whatwg.org/#parsing-main-incdata https://html.spec.whatwg.org/#parsing-main-incdata [4] https://html.spec.whatwg.org/#rawtext-state https://html.spec.whatwg.org/#rawtext-state [5] https://html.spec.whatwg.org/#rawtext-end-tag-name-state https://html.spec.whatwg.org/#rawtext-end-tag-name-state [6] https://html.spec.whatwg.org/#appropriate-end-tag-token https://html.spec.whatwg.org/#appropriate-end-tag-token
- ChrisSD 7y ago> Or at least if it's a bug, it's a bug in the HTML spec. Then again the HTML5 spec is based on what browsers already did, bugs included. Whether or not it's desirable behaviour or a bug is a moot point now. HTML is the way it is because of its history.