What is a Comment?
A comment is a string of code within HTML, XML, and CSS that is not viewed or acted upon by the browser or parser. It is simply in the code to provide information about the code or other feedback from the code developers.
Most programming languages have comments, they are used to:
- Describe and explain complicated code.
- Provide details about when the code was edited or reviewed.
- Remove sections of the code, but leave them available for later use.
- Chat with other developers working on the code.
Traditionally, comments in HTML are used for nearly anything, from explanations of complex table structures to sarcastic outtakes of the content of the page. Many developers use comments to hide portions of the page that are going to be used later. They are used to tell other people working on the page information about the page.
How to Write Comments
Writing comments in HTML, XHTML, and XML is very easy. Simply surround the text you want commented out with
In CSS, it's a little different, using C code comments rather than HTML:
<!-- and -->
/* commented text */
Comments are a Dying Art
Most programmers know the value of useful comments. Commented code makes it easier for code to be transferred from one team member to another. Comments help QA to test the code, because they can tell what the developer intended - even if it wasn't achieved. But with the popularity of Web authoring programs like Dreamweaver, comments are dying out in Web pages.
This is because the comments are really hard to see in most visual authoring tools. For example, rather than seeing, at the top of a Web page:
The visual tool shows a tiny icon to indicate that a comment is there. If the designer doesn't physically open the comment, he may never see it. And in the case of the above page, could cause problems if she edits the page and that editing is over-written by the script mentioned in the comment.
<!-- DO NOT EDIT THIS PAGE, IT'S AUTO-GENERATED BY A SCRIPT -->
What Can Be Done?
- Write meaningful and useful comments. Don't expect other people to read your comments if they are too long or don't include helpful information.
- As a developer, you should always review any comments you see on a page.
- Use tools provided by the authoring programs. Dreamweaver has page notes that are displayed every time a page is edited. And FrontPage has file summaries that can be viewed.
- Use content management to control how the pages are edited.
Even if you're the only person who edits your Web pages, comments can be useful. If you only edit a complicated page once a year, it's easy to forget how you built the table or put together the CSS. With comments, you don't have to remember, as it's written right there for you.