[contact-form-7 id="24078" title="Feedback EN"]

How to add/use comments in HTML, CSS, PHP, JS

This tutorial is going to show you how to add and use comments in PHP, HTML, CSS, JS files.

A comment is a string of code or text within HTML, XML, CSS, JS  and other programming languages that is not visible in your web browser. It serves to give some information about the code, to temporarily disable it, or to provide other feedback from the code developers.

HTML comment

Used to temporarily  comment out elements that you might need later without removing them, write notes inside HTML, for debugging. Add the opening comment tag  <!–  before your code and the closing tag — > after it.

Example:

  <!-- {%FOOTER_LINK} -->
  </div> 
  </div>
  </footer>
  </body>
  </html>

CSS comment

Used to easily switch on and off CSS blocks and make it easier to understand them. It starts with /* and ends with */.

Example:

  /* Global Structure---------------------------------------- */
  .main {
margin:0 auto;
width:940px;
position:relative;
/*
  h2 
font-size:26px;
line-height:28px;
}
*/ 

PHP comment

There are two types of comments you can add:

  1. single line comment used for quick notes about complex code or to temporarily disable a line of PHP code. You need to add // or # before the code.
  2. Example:

    //My comment goes here
    #define('TABLE_HEADING_WRITABLE', 'Writable');
  3. multi-line comment used to comment out large blocks of code or writing multiple line comments. You need to add /* before and */ after the code.
  4. Example:

    /*$Id$
    osCommerce, Open Source E-Commerce Solutions
    http://www.oscommerce.com
    Copyright (c) 2010 osCommerce
    Released under the GNU General Public License
      */

JavaScript comment

There are also two types of comments you can add:

  1. single line comments used to comment out single lines of code and writing small notes. You need to Add  // before your code or text. All text to the right of them will be ignored till the next line. Example:
    //verify if value is in the array
      function in_array(value, array)
      {
    for (var i in array)
    if (array[i] == value)
    return true;
    return false;
    }
  2. multi-line comments used to disable long segments of code. You need to add /* before your code and */ after it.

    Example:

  3. /*function in_array(value, array){
    for (var i in array)
    	if (array[i] == value)
    	return true;
            return false;}*/
    </script>
How to add/use comments in HTML, CSS, PHP, JS, 5.0 out of 5 based on 2 ratings