HTML Comments

 

HTML Comments

Comments in HTML are like little notes you leave in your code for yourself or other people. These notes help make the code easier to understand but don't show up on the actual website. The web browser just skips over them!

Key Points About HTML Comments

  • Comments are ignored by web browsers.
  • They aid in code readability and documentation.
  • HTML comments are denoted by <!-- content -->.
  • The shortcut key for commenting out code is Ctrl + /.
  • HTML supports both single-line and multi-line comments.

Types of Comments in HTML

HTML primarily supports two types of comments:

Single-line Comments

Single-line comments are contained within one line. They are useful for short annotations.

Example:

  <!-- This is a single-line comment -->

As you can see in the video below, the text inside the comment is not rendered

Multi-line Comments

Multi-line comments span across multiple lines, making them ideal for detailed explanations or temporarily disabling blocks of code.

Example:

  <!-- 
  This is a multi-line comment.
  It spans multiple lines.
  -->