SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
HTML
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10
Try this code live
Lesson 10 of 35

HTML Comments: How to Add Notes & Hide Code in HTML

3 min read · Free · No login needed

An HTML comment is a note you write in your code that the browser completely ignores. Visitors never see it. Only someone reading your source code can see it.

Diagram — see how it fits together
Infographic: HTML comments are hidden notes

A comment starts with <!-- and ends with -->:

<!-- This is a comment -->

Why use comments?

  • Notes for yourself: explain a tricky part of the page so future-you understands it.
  • Notes for your team: mark sections like <!-- Header starts here --> so others can find things fast.
  • Temporarily hiding code: comment out a section instead of deleting it, so you can bring it back later.

Rules to remember

Comments can span many lines. But never put -- inside a comment, because the browser will think the comment ends there. And remember: comments are visible to anyone who views your page source, so never put passwords, secret keys, or private information in a comment.

Tip: In VS Code, select any lines and press Ctrl + / to comment them out instantly. Press it again to remove the comment.

What a comment is

An HTML comment is a note you write for yourself (or for other developers) inside the code. The browser skips it completely — it never appears on the page. Comments start with <!-- and end with -->. Everything between those two marks is the comment.

Syntax

<!-- This is a comment. The browser ignores it. -->
<!--
  This comment runs over
  several lines.
-->
<h1>Hello</h1> <!-- a short note after the code -->

You can also use a comment to switch off a piece of code for a while. Instead of deleting a paragraph you might need later, wrap it in a comment — it stays in the file but disappears from the page.

<!-- <p>This paragraph is hidden for now.</p> -->
Note: Comments are invisible on the page, but anyone can see them by choosing "View page source" in the browser. Never write passwords, private notes, or anything secret in a comment.
Tip: Use a short comment at the start of each big section — <!-- Header starts here -->, <!-- Footer starts here -->. When a page grows long, these labels help you find your place in seconds.

Common mistakes

  • Putting -- inside a comment — the browser may end the comment early and show broken code.
  • Writing comments inside other comments — HTML does not allow nested comments.
  • Leaving dozens of old, commented-out blocks in a finished page — delete what you no longer need.
  • Forgetting to close a comment — everything after it disappears from the page until the next -->.

Example explained

  • <!-- This heading is the page title --> is a plain note for the developer. The browser skips it completely, so the visitor never sees it — only the <h1> below it shows.
  • <!-- <p>This paragraph is hidden...</p> --> wraps a whole paragraph in a comment, switching it off without deleting it. The page shows nothing from that line, but the code stays in the file for later.
  • <p>This paragraph is visible.</p> sits outside any comment, so it renders normally on the page.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Comments</title>
</head>
<body>

<!-- This heading is the page title -->
<h1>Welcome</h1>
<!-- <p>This paragraph is hidden and will not show.</p> -->
<p>This paragraph is visible.</p>

</body>
</html>

Output

Output — how it looks in the browser
Output of HTML Comments: How to Add Notes & Hide Code in HTML

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What is an HTML comment?

A note you write in your code that the browser completely ignores. Visitors never see it; only someone reading your source code can.

2. How do I write a comment in HTML?

Start with a less-than sign, an exclamation mark, and two hyphens, and end with two hyphens and a greater-than sign.

3. Can I put a password in an HTML comment?

No. Comments are invisible on the page, but anyone can see them by viewing the page source. Never put passwords or secrets in a comment.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Summer Training in Python Programming 2026
₹3,000
View
Full Stack PHP Development Course 2026
₹3,000
View
AI & ML with Azure AI, AWS AI & Generative AI
₹10,000
View
Browse all courses
HTML — Lessons
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →