Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Web Development - HTML Comments


HTML Comments

Comments are used to add notes, explanations, or reminders inside your HTML code. They are ignored by the browser and do not appear on the web page.


HTML Comment Syntax

To write a comment, use this syntax:

Syntax

<!-- Write your comments here -->

Notice that there is an exclamation mark ! in the start tag, but not in the end tag.

Tip: Use comments to describe your code, especially in longer files. This makes it easier to understand later.


Adding Comments

You can place comments anywhere in your HTML document - before elements, after elements, or even in between.

Example

Adding comments to your code:

<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Remember to add more information here later -->
Try it Yourself »

Hide Content with Comments

You can use comments to temporarily hide content from being displayed in the browser.

Example

Hiding an element:

<p>This is visible text.</p>
<!-- <p>This text is hidden.</p> -->
<p>This is visible again.</p>
Try it Yourself »

Everything between <!-- and --> will be hidden from the browser.


Hide Multiple Lines

You can also hide several lines of HTML at once by wrapping them inside comment tags.

Example

Hiding a section of code:

<p>This is visible.</p>
<!--
<p>This is hidden.</p>
<img src="avatar.png" alt="Example Image">
-->
<p>This is visible again.</p>
Try it Yourself »

Tip: Comments are great for debugging. You can comment out one line at a time to find what causes an error.


Hide Inline Content

Comments can also be placed inside a line of HTML to hide part of the text.

Example

Hide part of a paragraph:

<p>This <!-- hidden text --> is a paragraph.</p>
Try it Yourself »

Best Practices for Comments

  • Use comments to describe sections of your code.
  • Hide code temporarily when testing or debugging.
  • Do not overuse comments - short and clear is best.
  • Remove unnecessary comments before publishing your final page.

Summary

  • HTML comments start with <!-- and end with -->.
  • Comments are ignored by browsers.
  • You can use them to hide content or leave notes in your code.

Next, you'll learn how to add HTML Links - the clickable connections between web pages.

Next » HTML Links


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.