PDF download Download Article PDF download Download Article

A comment is a line of code that is not read by web browsers. Commenting your code allows you to leave reminders and explanations for yourself and any other coder that will be working on the page. Commenting can also be used to quickly disable parts of your code when you're testing or working on a new feature that isn't ready yet. Learning how to properly use comments will lead to more efficient coding, for you and your coworkers.

  1. Comments are designated by the tags <!-- and --> . You can insert quick comments to remind you what is happening with the code.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    Comment test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     <!-- This code makes a paragraph --> 
     < 
     p 
     > 
    This is the website </ 
     p 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
    • Make sure there are no spaces in the comment tags. For example < !-- will not activate the comment function. Inside the tags, you can have as many spaces as you'd like.
  2. Your comments can span multiple lines, which is useful for explaining complex code, or for blocking off large pieces of code.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    Comment test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     <!-- 
     Your comment can be as long as you need it to be. 
     Everything within the comment tags is kept from 
     affecting the code on the page. 
     --> 
     < 
     p 
     > 
    This is the website </ 
     p 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
    Advertisement
  3. If you're trying to track down a bug or want to keep code from running on the page, you can use the comment function to quickly block it off. That way, you can easily restore the code by deleting the comment tag.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    Comment test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     p 
     > 
    Check out these images </ 
     p 
     > 
     < 
     img 
     src 
     = 
     "/images/image1.jpg" 
     > 
     <!-- Hiding this image for now 
     <img src="/images/image2.jpg"> 
     --> 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  4. If you are programming in JavaScript or VBScript , you can use the comment function to hide the script on browsers that don't support it. Insert the comment at the start of the script, and end it with //--> to ensure that the script works on browsers that do support it.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     <!-- 
     document 
     . 
     write 
     ( 
     "Hello World!" 
     ) 
     //--> 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
    • The // in the end tag will prevent the script from executing the comment function if scripts are supported by the browser. [1]
  5. Advertisement

Community Q&A

Search
Add New Question
  • Question
    Where will the comment be saved?
    Joshua Liu
    Community Answer
    In the code. As the article said, it wont really show on the website, however it will be saved in the code.
  • Question
    How do you code it so people can add comments on your website about the actual thing?
    Free Eagle
    Community Answer
    Comments placed on your website are done in PHP & MySQL code, not HTML. If you have CPanel, you can go to your Softaculous Apps Installer and install an APP that will either create a bulletin board, guest book or even down load word press onto your site. These apps are already written PHP/MySql and you can turn off or on the comments.
  • Question
    How do I include comments in HTML?
    Free Eagle
    Community Answer
    You can include comments in your HTML code as follows: You will be able to see this when you're reading the code, but your comment will not show up in your viewer's browser.
See more answers
Ask a Question
      Advertisement

      Tips

      • Comment often as this will make it much easier to come back to your code later and remember how everything works.
      • HTML code can get messy quickly so you should use comments to structure your code. Add comments at the start and the end of code sections to make it easy to find.
      • If you sometimes find yourself looking at PHP, learn how to comment in PHP as well.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      Thanks to all authors for creating a page that has been read 304,440 times.

      Is this article up to date?

      Advertisement