HTML Comments


HTML comments are used to add notes or explanations inside the code. Comments are not displayed in the browser and are ignored when the page is rendered.

Comments help developers understand code and make it easier to maintain and debug.

Syntax of HTML Comments

HTML comments start with <!-- and end with -->.

Anything written inside these symbols will be treated as a comment.

In this example, the comment explains the code but does not appear on the webpage.

Only the paragraph content is displayed in the browser.

Why Use HTML Comments

Comments are useful for:

  • Explaining complex sections of code
  • Temporarily disabling code
  • Adding reminders for future updates
  • Improving team collaboration

The code inside the comment will not be executed or displayed by the browser.

This technique is useful when testing or debugging layouts.

Best Practices for HTML Comments

  • Use comments to explain important sections
  • Avoid unnecessary or excessive comments
  • Do not include sensitive information in comments
  • Remove unused comments in production code

Why Comments Matter for Jobs

Professional developers are expected to write readable and maintainable code.

Good commenting practices help teams understand code faster and reduce errors in large projects.

Practice Task

Add comments to an HTML file explaining the purpose of the head and body sections.

What You Will Learn Next

In the next lesson, you will learn best practices for writing clean and professional HTML text content.