HTML Comments
You can already write headings and paragraphs that visitors see. Sometimes you need a note for yourself or your team that should not appear on the page. HTML comments solve that. This session shows the comment syntax and when to use it carefully.
What is an HTML comment?
An HTML comment is text wrapped between <!-- and -->. The browser parses it as a comment and does not show it as visible page content. Comments are useful for short reminders, section labels in the source, or temporarily turning off a piece of markup while you test.
Direct answer
Write a comment like this: <!-- your note here -->. Anything between the opening <!-- and the closing --> stays in the source file but is not rendered as normal text, headings, or paragraphs for visitors. View source or open DevTools if you need to confirm a comment is still in the file.
A simple comment
html<!-- This note is only for developers -->
<p>This paragraph is visible on the page.</p>
Reading the example
- The first line is a comment — visitors do not see that sentence on the page
- The paragraph below is normal visible content
- Both lines remain in the HTML file when you save it
Multi-line comments and temporary hide
Comments can span more than one line. A common beginner use is to wrap a block you want to disable temporarily, instead of deleting it. Later you can remove the comment markers to bring the markup back. Keep temporary blocks short so the file stays readable.
Commenting out a block
html<h1>Visible Title</h1>
<!--
<p>This paragraph is hidden while testing.</p>
<p>So is this one.</p>
-->
<p>This paragraph still shows.</p>
Comments are not security
Anyone can open View Source and read your comments. Do not put passwords, private keys, or secret API tokens in HTML comments. Comments are for development notes, not for hiding sensitive data.
Try it yourself
- Open your HTML practice file
- Add a short comment above a paragraph explaining what the paragraph is for
- Wrap one paragraph in a multi-line comment to hide it temporarily
- Save and open the page — confirm only the uncommented content is visible
- Use View Source (or your editor) to confirm the comment text is still in the file
Common mistakes
- Forgetting the closing
-->so later content disappears or breaks - Putting passwords or secrets inside comments
- Leaving huge commented blocks in production pages for a long time
- Expecting comments to hide content from View Source (they do not)
- Using comments instead of real headings or paragraphs for visitor-facing text
Summary
- HTML comments use
<!--and--> - Comment text is not shown as visible page content
- Use comments for notes, section hints, or short temporary hide
- Multi-line comments can wrap a small block while testing
- Comments are visible in the source — never store secrets there
- Prefer clear live markup for text that visitors should read
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top