Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yep 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 [2] https://html.spec.whatwg.org/#generic-raw-text-element-parsi... [3] https://html.spec.whatwg.org/#parsing-main-incdata [4] https://html.spec.whatwg.org/#rawtext-state [5] https://html.spec.whatwg.org/#rawtext-end-tag-name-state [6] https://html.spec.whatwg.org/#appropriate-end-tag-token




> 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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: