While working on FHM.com earlier today I came across an odd bug on a page. On Firefox 3, parts of the page were rendering incorrectly, while on Internet Explorer everything was fine.
Browsers rendering content differently isn’t anything new, but most of this site is derived from common templates, and only a small part of the page was directly inserting HTML. This was the obvious place to look.
Looking at the source code with syntax highlighting turned on revealed the problem, and it was one i’d not come across before.
The site had a comment that included two dashes next to each other, something like this
<-- A test comment -- test -->
Looks OK doesn’t it? Well it’s not valid XHTML, hence the problem.
XHTML is based on XML so follows it’s standards. Here is the standard for XML comments.
The key wording here is, the string ” — ” (double-hyphen) MUST NOT occur within comments.
The same applies to HTML, have a look at what the HTML4 spec says about comments. This is down to HTML being based on SGML, and double dashes are SGML comments.
In the end, it’s Firefox obeying the spec, and other browsers not. However, things look like they are due to change.
Due to these problems, SGML comments have been removed from Acid 2, and future HTML versions will not require SGML comments. Browsers that have implemented them are now expected to remove their support for SGML comments, for all HTML versions.
Read more about HTML and SGML comments.