I'm seeing conflicting documentation and opinions on whether "--" is still invalid in an HTML comment. Most of the documentation I've seen on this is 5-10 or more years old. Consider the following simplified code in HTML using BEM syntax for CSS class names.
<html>
<head>
<meta charset="utf-8">
<title>Page</title>
</head>
<body>
<div>
<header>
<div>
<div>
<div><a href="/">link</a></div>
<!-- <div class="block__element--modifier"></div> -->
<div></div>
<div></div>
</div>
</div>
</header>
</div>
</body>
</html>
I'm looking at using a parser that reads this and autocloses my header producing this resulting output. Looking at the code it is identifying the "--" in the commented class as the close of the comment, the commented closing div tag gets consumed, and later it determines that the level requires that the header be closed.
<html>
<head>
<meta charset="utf-8">
<title>Page</title>
</head>
<body>
<div>
<header>
<div>
<div>
<div><a href="/">link</a></div>
<!-- <div class="block__element--modifier"></div> -->
<div></div>
<div></div>
</div>
</header>
</div>
</header>
</div>
</body>
</html>
While leaving commented code isn't the best, this is a completely normal thing within the typical development cycle. In our case this output causes a very broken rending of this page.
This output is obviously not correct, but I want to understand what should be correct. According to this and other posts there is the idea that "--" or double hyphens shouldn't be used in HTML because it isn't allowed in XML. Indeed, the HTML4 spec discourages this, but it appears HTML5 doesn't make this same distinction. I've always had the understanding that XML logic and parsing really shouldn't be used for HTML because it isn't actually a subset of xml. In fact I've never been happy when I've gone down that path .
The impact here is that BEM is a common convention and if the current HTML spec forbids this we may want to avoid BEM or modify it for future use. While HTML and parsers are by default pretty forgiving, sticking to the spec is typically a best practice for future stability. Thoughts?