HTML comments let you place notes in the source code without displaying them as normal page content.
<!-- This is an HTML comment -->
<p>Visitors can see this paragraph.</p>
An HTML comment starts with <!-- and ends with -->.
> character does not end an HTML comment. The closing delimiter is -->.The syntax is:
<!-- comment text -->
The browser recognizes the complete opening and closing delimiters. Do not confuse the final --> with a single greater-than sign.
Here is a corrected version of the original Plus2net example:
<!-- Line 1: this text is commented and is not displayed -->
<br>Line 2: this line is visible
<!-- Line 3: plus2net, this is also a comment -->
<!-- plus2net --> Line 4: this text is outside the comment
<br>
Hello
The browser displays:
Line 2: this line is visible
Line 4: this text is outside the comment
Hello
The commented text remains in the HTML source but is not rendered as normal page content.
An HTML comment can span several lines:
<!--
This is line 1 of the comment.
This is line 2 of the comment.
This is line 3 of the comment.
-->
<p>This paragraph is outside the comment.</p>
You do not need a separate comment delimiter for every line.
HTML comments are sent to the browser as part of the page source. A visitor can inspect the HTML and read them.
<!-- Internal note: revise this section later -->
Comments can help developers understand or maintain a document when the note provides real context.
<!-- Main navigation starts here -->
<nav>
...
</nav>
<!-- Product comparison section -->
<section>
...
</section>
Useful comments may explain:
Avoid comments that merely repeat what obvious markup already says.
Because HTML comments are part of the client-side source, do not use them to hide confidential information.
<!-- Do not store passwords, tokens or private keys here. -->
Also avoid relying on comments as a permanent method for disabling large sections of complicated markup. Version control is better for preserving removed code.
HTML comments should not be nested inside one another.
Avoid this:
<!-- Outer comment
<!-- Inner comment -->
-->
The inner comment delimiters interfere with the intended comment structure and can produce confusing parsing results.
Use one comment block instead:
<!--
Outer note
Inner note
-->
HTML comments and server-side PHP comments behave differently.
<!-- This comment is sent to the browser source. -->
<?php
// This comment is processed on the server and is not sent as page output.
?>
If a PHP comment stays inside PHP code and is not explicitly output, visitors do not receive that comment in the generated HTML.
See comments in PHP.
It does not. The proper closing delimiter is -->.
Correct:
<!-- Comment -->
Incorrect examples:
<! Comment >
<-- Comment -->
<!-- Comment >
Do not place another <!-- ... --> block inside an HTML comment.
HTML comments can be read through View Source or developer tools.
Comments are most useful when they explain something that is not already obvious from the markup itself.
Start the comment with <!-- and end it with -->.
No. A comment ends with the complete closing delimiter -->.
Yes. One comment block can contain text across several lines.
Yes. HTML comments are not rendered as normal page content, but they remain visible in the page source.
No. Avoid placing one HTML comment inside another comment.
No. Never store secrets in HTML comments because the browser receives the source.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.