html
/

HTML Comments: Writing Notes in Code

Last Sync: Today

On this page

10
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

html

HTML Comments: Writing Notes in Code

What are HTML Comments?

HTML comments are used to add notes or explanations in your code. They are ignored by browsers and are not displayed on the webpage.

Syntax

HTMLRead-only
1
<!-- This is a comment -->

Single Line Comment

HTMLRead-only
1
<!-- This is a single-line comment -->

Multi-line Comment

HTMLRead-only
1
<!--
  This is a multi-line comment
  It can span multiple lines
-->

Commenting Out Code

HTMLRead-only
1
<!-- <p>This paragraph is hidden</p> -->

Use Cases

  • Explain code sections
  • Temporarily disable code
  • Add notes for developers
  • Debug issues

Best Practices

  • Keep comments clear and meaningful
  • Avoid over-commenting obvious code
  • Use comments for complex logic explanation
  • Remove unnecessary comments before production

Common Mistakes

  • Leaving sensitive information in comments
  • Overusing comments instead of writing clean code
  • Incorrect syntax (missing <!-- or -->)
  • Commenting large unused code blocks unnecessarily

Important Note

Even though comments are not visible on the page, they can still be viewed in the browser's page source. Avoid placing sensitive information inside comments.

Conclusion

HTML comments help improve code readability and maintainability when used correctly.

Try it yourself

<!-- This is a comment -->
<p>Hello World</p>

Test Your Knowledge

Q1
of 3

What is the correct comment syntax?

A
// comment
B
<!-- comment -->
C
# comment
D
/* comment */
Q2
of 3

Are comments visible in browser?

A
Yes
B
No
C
Sometimes
D
Only in mobile
Q3
of 3

Where can comments be seen?

A
UI
B
Console
C
Page source
D
CSS

Frequently Asked Questions

Are HTML comments visible to users?

No, but they can be seen in the page source.

Can comments span multiple lines?

Yes, using multi-line comment syntax.

Should comments be used in production?

Yes, but avoid unnecessary or sensitive information.

Previous

html best practices

Next

html entities

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.