HTML Tutorial · Lesson 09

Comments

Learn how HTML comments work, why they are useful, and how to write single-line and multi-line comments in your code.

FREE

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 simply skips over them.

Key Points About HTML Comments

  • Comments are ignored by web browsers.
  • They help improve code readability and documentation.
  • HTML comments are written using <!-- content -->.
  • The common keyboard shortcut for commenting out code in many code editors is Ctrl + /.
  • HTML supports both single-line and multi-line comments.

Types of Comments in HTML

HTML primarily supports two ways of writing comments: single-line comments and multi-line comments.

Single-line Comments

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

Example:

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

The text inside the comment is not rendered on the webpage. The browser ignores the comment when displaying the page.

Multi-line Comments

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

Example:

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