Changes in HTML 5 - HTML Comments
What's new in HTML 5
Differences between HTML 5 and earlier versions of HTML
Issues with HTML comments
When comment code appears where text content is expected, such as in a <title>
tag, which is one of the tags that expect text content, whether or not it is treated as comments depends on how the HTML document is being parsed. When it is being parsed as legacy HTML (for example, by IE 8 and some search engine crawlers), the code will be included in the text content. When the HTML document is being parsed as either xHTML, the XML serialization of HTML, or pure XML, the code will be treated as comments and will not appear in the displayed text. To avoid this, do not code comments in the <title>
tag or other text content.
To escape text containing the comment delimiters (<!--
) in text content so that it appears for all browsers, use a <![CDATA[...]]>
section instead.