Examples of HTML Comments
Examples of comments in HTML 5
Comments in HTML Documents
<!-- This will be ignored - - it's a comment! -->
The space between the hyphens in the middle is required because two adjacent hyphens (--
) are not permitted in comments.
<!-- changed to use <abbr> because <acronym> is deprecated: <acronym>--><abbr>HTML<!--</acronym>--></abbr>
In this example, the starting <abbr> tag and ending </abbr> tags actually do match up even though they look like they are not properly nested.
<!-- <script type="text/javascript"> window.onload=alert("This won't happen.") </script> -->
<script type="text/javascript"> <!-- window.onload=alert("Hello JavaScript World!") // --> </script>
In this case the alert will be displayed if JavaScript is enabled. The comments will only hide the JavaScript code from browsers without JavaScript support or with scripts disabled. In some cases, browsers give the user an option to disable scripts.
Comments in HTML Templates
<xsl:template name="html-navigation-template"> <!-- no parameters --> <xsl:if test="not(html:nav)"> <xsl:comment> Missing web page navigation section! </xsl:comment> </xsl:if> <xsl:apply-templates select="html:nav"/> </xsl:template>
The XSLT comment (<!-- no parameters -->
) will appear in the template but not in the HTML code. The comment inside the xsl:comment element will appear only when the template is used to transform the HTML document on the server side or, if transformed on the client, when viewing the HTML code for the result document.