Adding Comments within your HTML Documents

Tuesday, February 7, 2012

The comment tag is used to insert comments in the source code. Comments are not meant to be displayed in the when the webpage is rendered by the web browser. It is a good practice to use comments to add notes to your HTML code. Doing so can help you when you edit the source code at a later time.

To add a comment in your code, you start the comment you use the following sequence of characters: <!--, and to end the comment you use the following sequence of characters: -->, such as in this <!-- example of a comment. -->

It is also a good idea to use comment to your scripting code. This is to ensure that the code does not display as text for browsers that do not have support for the client side scripting language. Here is an example:

<script type="text/javascript">
    function popUp() {
        alert("How are you today!")

Note: To ensure that browsers do not render comments and handle them appropriately, make sure the comments begin with "<!--", end with "-->" and do not contain "--" or ">" within the comment.

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

HTML CSS: The Complete Reference Creating Web Pages Simplified HTML CSS and JavaScript Editor