HTML Comments

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 -->.

Important correction: a plain > character does not end an HTML comment. The closing delimiter is -->.

HTML Comment Syntax Top ↑

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.

Basic Comment Example Top ↑

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.

Multiline Comments Top ↑

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.

Comments Are Visible in Page Source Top ↑

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 -->
Do not place passwords, API keys, private instructions, unpublished credentials or other secrets inside HTML comments. Hiding text from the rendered page does not make it private.

Good Uses for HTML Comments Top ↑

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:

  • why an unusual markup decision exists,
  • where a large section begins or ends,
  • a temporary development note that is safe to expose publicly.

Avoid comments that merely repeat what obvious markup already says.

What Not to Put in HTML Comments Top ↑

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.

Do Not Nest HTML Comments Top ↑

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 vs PHP Comments Top ↑

HTML comments and server-side PHP comments behave differently.

HTML comment Top ↑

<!-- This comment is sent to the browser source. -->

PHP comment Top ↑

<?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.

Common HTML Comment Mistakes Top ↑

Thinking any > character closes the comment Top ↑

It does not. The proper closing delimiter is -->.

Using the wrong opening or closing characters Top ↑

Correct:

<!-- Comment -->

Incorrect examples:

<! Comment >
<-- Comment -->
<!-- Comment >

Nesting comments Top ↑

Do not place another <!-- ... --> block inside an HTML comment.

Putting secrets in comments Top ↑

HTML comments can be read through View Source or developer tools.

Using comments instead of explaining code clearly Top ↑

Comments are most useful when they explain something that is not already obvious from the markup itself.

Frequently Asked Questions Top ↑

Q1: What is the syntax for an HTML comment?

Start the comment with <!-- and end it with -->.

Q2: Does a greater-than sign end an HTML comment?

No. A comment ends with the complete closing delimiter -->.

Q3: Can an HTML comment span multiple lines?

Yes. One comment block can contain text across several lines.

Q4: Can visitors see HTML comments?

Yes. HTML comments are not rendered as normal page content, but they remain visible in the page source.

Q5: Can HTML comments be nested?

No. Avoid placing one HTML comment inside another comment.

Q6: Are HTML comments safe for passwords or API keys?

No. Never store secrets in HTML comments because the browser receives the source.


HTML Meta Tags BODY tag



plus2net.com










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer