Cover Image for HTML Comments
160 views

HTML Comments

HTML comments are a way to add notes and explanations to your code that won’t be displayed in the browser. Comments can be useful for documenting your code, providing reminders, and temporarily disabling code that you don’t want to delete.


Here’s the syntax for adding a comment in HTML:

<!-- This is a comment -->

Comments start with <!-- and end with -->. Anything between these delimiters will be treated as a comment and ignored by the browser.


For example, you might use comments to explain the purpose of a section of code:

<div>
  <!-- This section contains the main content of the page -->
  <h1>Welcome to my website</h1>
  <p>This is where I'll share my thoughts and ideas with you.</p>
</div>


Or you might use comments to temporarily disable a piece of code for testing or debugging:

<div>
  <h1>Welcome to my website</h1>
  <!--
  <p>This paragraph is temporarily disabled.</p>
  -->
  <p>Check back soon for more updates!</p>
</div>

In this example, the second paragraph has been commented out, so it won’t be displayed in the browser. This can be useful for testing how your page looks without a particular element or section.

Keep in mind that while comments are useful for documenting your code, you should use them sparingly and only for information that’s relevant and helpful. Overuse of comments can make your code harder to read and understand.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS