Welcome to WebHeadStart.org

Web Technologies

Sponsored By

WebHeadStart.org is currently in beta.
Please pardon our appearance as we work to provide you with the most comprehensive reference on today's web technologies.

Interested in advertising on WebHeadStart? Become an advertising partner today!

XHTML Comments

You can add comments to your XHTML documents to remind yourself, or to document to others what you were trying to do in your Web page. XHTML comments only appear in the page source, and are invisible to users browsing your page - i.e. Web browsers ignore the contents of XHTML comments. An XHTML comment example is shown here:

Code Sample:
<!-- This is an example of a comment -->
<html>
    <head><title>XHTML Comment Example</title></head>
    <body>
        <h1>Documenting Web Pages with XHTML Comments</h1>
        <p>XHTML comments are a useful way for Web developers to make notes to themselves.</p>
        <!-- This comment is invisible to visitors. -->
    </body>
</html>
<!-- (c) Copyright 2005, All Rights Reserved -->
view code in new window.
render sample in browser.
Download code sample on your computer.

To add a comment into your XHTML page:

  • Go to the location in your XHTML document where you wish to insert a comment. Start the comment by typing "<!--"
  • Type your comments.
  • When you are finished, type "-->" to close the comment tag.

You can put comments anywhere in an XHTML document, and insert just about anything at all within them. Here's what the above XHTML code would look like in a browser - notice how the contents of all the XHTML comment tags were completely ignored by the browser:

Code Sample — browser view

In summary, XHTML comments can be used anywhere in a Web page to help the author(s) understand the source code - they remain invisible to the web page viewer. Here are some common usages and ticks:

  • Comments are particularly useful for describing what you are working on in advanced HTML layouts, or for describing unfinshed work in progress.
  • You can use an XHTML comment to temporarily remove an entire section from a page.
  • Comments are not invisible to the public, they are simply not rendered by a Web browser. It's very easy for anyone to view the XHTML source and read your comments, so don't write any sensitive information like passwords in a comment field.
  • Comments may not have nested comments.
  • XHTML comments are a handy way to keep track of different revisions.
Start Of Section: XHTML Tutorial Start of Section:
XHTML Tutorial
Previous Page: XHTML Form Previous Page:
XHTML Form
Next Page:
XHTML Divisions
Next Page: XHTML Divisions
Valid XHTML 1.0! Valid CSS! Site Map | Privacy Policy | Terms of Use | WebHeadStart.org © 2005 All Rights Reserved.