Jump to content

HyperText Markup Language/Comments

From Wikibooks, open books for an open world

HTML offers the possibility to insert comments into the page. To place a comment in your HTML code, start it with <!-- and close it with -->. An example:

    <p>The first paragraph.</p>
    <!-- This comment spans one line, and will not be displayed to the browser. -->
    <p>The second paragraph.</p>
    <!--
       This comment spans multiple lines,
       and will also not be displayed to the browser.
    -->
    <p>The third paragraph.</p>

Unlike notes in office suites, comments are completely ignored by browsers, so the readers of the page have no idea of their presence. They can be viewed in the source of the web page though.

You should avoid nested comments, as these can cause troubles to many browsers. An example:

    <p>The second paragraph.</p>
    <!--
      <!--
       Nested comments should better be avoided.
        -->
    -->
    <p>The third paragraph.</p>