🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEhtml

html Documentation

LOADING ENGINE...

HTML Comments

AI & DATA SCIENCE // comments-html

HTML comments (<!-- ... -->) are notes in the source code that the browser parses but never renders or executes.

Syntax

<!-- This is a comment -->
<!--
  Multi-line
  comment
-->

Deep Dive Course

HTML comments start with **`<!--`** and end with **`-->`**. The browser's parser reads them but does not display them or run any code inside them — they exist purely for developers reading the source. Unlike JavaScript comments, HTML comments can span multiple lines without special syntax, and they are still visible to anyone who views the page source, so they are not a way to hide sensitive information.

1Understanding HTML Comments

HTML comments start with `<!--` and end with `-->`. The browser's parser reads them but does not display them or run any code inside them — they exist purely for developers reading the source. Unlike JavaScript comments, HTML comments can span multiple lines without special syntax, and they are still visible to anyone who views the page source, so they are not a way to hide sensitive information.

💡

Comments in HTML are visible to any visitor who opens 'View Page Source' — never leave API keys, internal notes, or credentials inside them.

editor.html
<!-- Header section -->
<header>
  <h1>My Site</h1>
</header>
<!-- End header -->

<!-- TODO: add the pricing table here -->
localhost:3000

2Practical Example

Here is a real-world application of HTML Comments showing how it is used in production HTML.

editor.html
<!--
  Conditional comments (IE-only, deprecated):
  modern browsers ignore these entirely.
-->
<p>Visible paragraph</p>
localhost:3000

3Best Practices

Follow these guidelines when working with HTML Comments:

1. Use comments to mark the start/end of large sections, e.g. <!-- Navbar -->

2. Remove leftover commented-out code before shipping to production

3. Never put secrets or sensitive notes inside HTML comments

⚠️

Tip: Comments in HTML are visible to any visitor who opens 'View Page Source' — never leave API keys, internal notes, or credentials inside them.

editor.html
<!-- Header section -->
<header>
  <h1>My Site</h1>
</header>
<!-- End header -->

<!-- TODO: add the pricing table here -->
localhost:3000

Examples

Example 01Basic Usage
<!-- Header section -->
<header>
  <h1>My Site</h1>
</header>
<!-- End header -->

<!-- TODO: add the pricing table here -->
Example 02Advanced Example
<!--
  Conditional comments (IE-only, deprecated):
  modern browsers ignore these entirely.
-->
<p>Visible paragraph</p>

Best Practices

  • Use comments to mark the start/end of large sections, e.g.
  • Remove leftover commented-out code before shipping to production
  • Never put secrets or sensitive notes inside HTML comments

Interview Question

Can HTML comments be nested, and are they hidden from users?

Hint: Think about how the parser looks for the closing '-->' and where the browser's DevTools fit in.

HTML comments cannot be nested — the parser stops at the very first '-->' it finds, so a comment inside a comment breaks the outer one. They are hidden from the RENDERED page, but not from the user entirely: anyone can see them via 'View Page Source' or DevTools, so they should never contain sensitive information.

Exercises

EasyPractice using HTML Comments in a real scenario.
View Solution
<!-- Header section -->
<header>
  <h1>My Site</h1>
</header>
<!-- End header -->

<!-- TODO: add the pricing table here -->

Frequently Asked Questions

Can HTML comments be nested, and are they hidden from users?

HTML comments cannot be nested — the parser stops at the very first '-->' it finds, so a comment inside a comment breaks the outer one. They are hidden from the RENDERED page, but not from the user entirely: anyone can see them via 'View Page Source' or DevTools, so they should never contain sensitive information.

Related Functions

helloworldhtml-tag