Where & How To Comment Out HTML or PHP?

If you have ever seen anything like <!– I am a comment –> then you will know what an html comment is.

This is a quick post to show how to do html comments and when you should use them.

Here is an html comment.

<!-- I am an html comment. -->

Notice the opening tag starts with an exclamation mark, but the closing tag does not. If you are creating a static html website then these could come in handy for marking where the header and footer is on your page or a navigation.

Where Can I Use HTML Comments?

Naturally you can only use HTML comments inside html, not server side code or css, but you can generally use them anywhere you like, as long as they are not nested inside of each other you should be fine.

Should I Use HTML Comments?

My personal preference is not to use them unless my website is static html. If you are using PHP then generally you probably won’t need html comments as they just add bloat to the page and you can use php comments instead which are removed when the server processes the page.

<?php

// This is a single line comment, free to use!

# This is a single line comment, PEAR standards say not to use these.

/* 
* This is
* a multi
* line comment 
*/

/**
* This is a doc
* block comment
* notice the extra asterix
**/

?>

Good luck with your websites and keep on coding!

Comments