Why can I close the style tag from CSS comments?

Why does <\ style> in the comments violate inline styles?
I thought I could write there what I want!

<!doctype html>
<meta charset="utf-8">
<title>test</title>

<style>

/*
</style>
<h1>HTML!</h1>
<style>
*/

</style>

You can see it in action here .

+4
source share
1 answer

HTML is parsed first. This is why you can see <\/b>in JavaScript that works with HTML: older browsers used </the "end of script block" token (newer ones specifically look for </script>).

So, HTML is parsed, and the result consists of two elements <style>, one with an initial comment and the other with an end comment.

, HTML:

<style><!--
    /* Whatever you want here! */
--></style>

, .

+5

Source: https://habr.com/ru/post/1524318/


All Articles