Content · Web Development · HTML

HTML Comments: Syntax and Safe Usage

Comments are notes for people reading the source code, not text visitors see on the page. HTML comments start with <!-- and end with -->.

1 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

Comments are notes for people reading the source code, not text visitors see on the page. HTML comments start with <!-- and end with -->.

What You Need to Know


Comments are still visible to anyone who views the source. Never put passwords, private details, or API keys inside them; use them for short, useful notes about the markup.

Example: See It in Action


Try this markup in a fresh practice file. The next section explains the parts worth paying attention to.

This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.

<!-- This section introduces the project. -->
<section>
    <h2>About the project</h2>
    <p>It is a small school project.</p>
</section>

Let’s Understand the Example


  • Section groups content around a shared topic and usually has a heading.
  • An h2 starts a major section beneath the page topic.
  • A p groups a paragraph of related text. Start another paragraph for a new thought.

You should see a readable heading and its related content. The heading level tells readers how the ideas fit together, not merely how large the letters look.

What Should You See?


The page should display “About the project” as a heading, followed by its related content. Change the heading text and refresh the browser to see the result.

Read only the headings, from top to bottom. Do they tell a sensible story? If not, move sections or choose levels that match the content.

Try It Yourself


  1. Add one helpful comment above a section, then check that it does not appear as visible page text.
  2. Save your changes, open or refresh the page, and compare the result with the original example.
  3. Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.

Common Beginner Mistakes


  • Using comments as a place to hide information that visitors must not receive.
  • Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.

Key Takeaways


  • Comments are notes for people reading the source code, not text visitors see on the page.
  • Section groups content around a shared topic and usually has a heading.
  • Comments are still visible to anyone who views the source. Never put passwords, private details, or API keys inside them; use them for short, useful notes about the markup.
Share this resourceSend this page to someone who may find it useful.