HOW-TO

How to comment in HTML (and what to remove before you share the page)

The comment syntax, the keyboard shortcut, commenting out a block, CSS and JavaScript comments inside an HTML file, and why anyone with the link can read your comments.

4 min read·

An HTML comment starts with <!-- and ends with -->. The browser skips everything between them, so the text does not appear on the page. People use comments to leave notes in the code or to hide part of a page without deleting it.

Write a comment

Type this anywhere inside the file:

<!-- Pricing section starts here -->

A comment can run over several lines. Everything up to the next --> is hidden:

<!-- TODO: swap in the new logo before Friday -->

In VS Code and most code editors, Ctrl+/ on Windows or Cmd+/ on a Mac turns the selected lines into a comment, and pressing it again turns them back.

Comment out part of a page

To hide a section for now, wrap it in a comment:

<!-- <section id="testimonials"> ... </section> -->

Save and reload. The section is gone from the page but still in the file, so you can bring it back by removing the <!-- and -->.

Comments inside style and script tags

  • ✓Inside <style> or a .css file, HTML comments do not work. Use /* like this */.
  • ✓Inside <script> or a .js file, use // for one line or /* ... */ for several.
  • ✓Using <!-- --> in CSS breaks the next rule; using /* */ in plain HTML shows the slashes and stars on the page.

When a comment breaks the page

  • ✓Half the page disappeared: a comment was opened with <!-- and never closed, so everything after it is hidden. Find the opening and add -->.
  • ✓Text like --> shows on the page: one comment was put inside another. HTML comments cannot be nested; the first --> ends the outer one. Remove the inner comment first.
  • ✓A stray > or -- shows up: the comment was typed as <!- or -- >. It needs exactly <!-- to open and --> to close, with no space.

Comments are not private

Comments are hidden on the page, not from people. Anyone who opens the page can right-click, choose View Page Source and read every comment. That includes notes like "client said budget is flexible", old prices, email addresses and API keys left in a commented-out script.

Before you send the page, search the file for <!--, /* and // and delete anything you would not say to the person opening it. Pages made by AI tools often contain notes too, so check those as well.

Share it as a link

With FileShare Pro you upload the .html file from the dashboard, copy the link and send it. It opens as a page in any browser, on phones too, and the person opening it needs no account. If you find a comment you missed, upload the cleaned version to the same link. Want the people you send it to to leave notes on the page instead of in the code? See letting people comment on a web page. Sign up free to share your first page.

Frequently asked

How do I comment in HTML?

Wrap the text in <!-- and -->, for example <!-- note -->. The browser does not show anything between them.

What is the shortcut to comment in HTML?

In VS Code and most editors, select the lines and press Ctrl+/ on Windows or Cmd+/ on a Mac. Press it again to uncomment.

Can people see HTML comments?

Not on the page, but anyone can read them with View Page Source. Remove private notes, prices and keys before you share the file.

Can you nest HTML comments?

No. The first --> closes the comment, so anything after it shows on the page. Remove inner comments before commenting out a larger block.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free