Web Development
Learn HTML5
Adding Comments In HTML

Adding Comments in HTML

Comments are like annotations in a book. They are used to explain more about the code, and to give future developers of your app more information about what the code does...At least that's the main purpose of comments.

You will find yourself using comments to debug your code, to disable parts of your code that you don't want to execute, or to leave a ToDo list for yourself.

Comments are ignored by compilers and interpreters when they are executed. Compilers and interpreters are applications used to execute code.

The web browser can be considered an interpreter because it takes what we write in HTML and executes what we have been coding.

We add comments in HTML by using the following syntax

<!-- Type comment here -->

That's it! Any text you write in the space between the four hyphens will be considered a comment and skipped over. You can use this to disable parts of your code that you don't want to execute for reasons such as it causes an error in the application. For example:

<!-- 
  <section>
    This section causes the web app to behave in an unwanted way.
    Therefore, it is commented out
  </section>
 -->

The comment syntax in HTML can be used as a single-line comment, or a multi-line comment. Other programming languages have different definitions for single-line comments and multi-line comments.