It is a very good working practice to comment your code in HTML Comments serve two major functions:
- As notes and reminders
Comments allow you leave yourself notes as to what sections of code do, and what they are there for. It is common for a developer to return to code that has not been touched in six months or more: comments allow you to quickly remember what each piece of code does.
- As “traffic cones” around code that is problematic
Code surrounded by comment markup immediately ceases to work. Because HTML code is read from the top down, you can narrow down the cause of problems by removing sections from execution by surrounding them with comments, moving the start and ending comment markup around to analyse problems via a process of elimination.
Content, markup and code within comments does not appear on a web page, but can still be read by anyone with access to your source code. (In HTML this is as easy as using View / Source in the browser).
<!-- this is an HTML comment -->
Note that HTML comments are not tags; this can be confusing to many neophyte coders, as they appear to break all the rules of HTML. Comments may be placed over multiple lines.
<!-- this is a comment
over multiple lines -->