📌 HTML Comments

General Purpose

The main purpose of HTML comments is to guide the person who writes or later edits the code. For example, they are used to explain what a section does, leave notes for future updates, or make complex structures easier to understand. They are also very useful for temporarily disabling parts of the code.

Writing HTML Comments

In HTML, a special structure is used to write comments:

HTML
<!-- Write your comment here -->

A comment starts with <!-- and ends with --> Anything written between these tags will not be displayed in the browser.

Example:

HTML
<!-- Write your comment here -->
<p>This is a paragraph.</p>
<!-- Remember to add more information here -->

These comments are only visible to people who view the source code.

Hiding Content / Disabling Code

Comments can also be used to temporarily remove parts of the code. This is especially useful for debugging.

Hiding a single line:

HTML
<p>This is a paragraph.</p>
<!-- <p> This paragraph is hidden </p> -->   
<p>This is another paragraph.</p>

It is possible to disable multiple lines of code at once.

Inline Comment

Comments can also be used within a line:

HTML
<p>This <!-- < important --> is a paragraph.</p>
<!-- <p> This paragraph is hidden </p> -->   
<p>This is another paragraph.</p>

Here, the word “important” is hidden. The result in the browser will be:

  • Benefits of Comments

  • HTML comments are useful for:
  • Adding explanations: To describe what the code does
  • Debugging: To temporarily disable problematic parts
  • Temporary changes: To hide elements during design updates

In short, HTML comments are invisible to users but act like helpful notes for developers. They significantly improve code readability, especially in large projects.