- Web templates
- E-commerce Templates
- CMS & Blog Templates
- Facebook Templates
- Website Builders
How to add/use comments in HTML, CSS, PHP, JS
August 3, 2012
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:
- 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.
- 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.
Example:
//My comment goes here #define('TABLE_HEADING_WRITABLE', 'Writable');
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:
- 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; }
- multi-line comments used to disable long segments of code. You need to add /* before your code and */ after it.
Example:
/*function in_array(value, array){ for (var i in array) if (array[i] == value) return true; return false;}*/ </script>