MyInternships.in

HTML Basics

HTML Comments

HTML comments let you leave notes inside your code that the browser ignores and visitors never see. They are perfect for explaining your markup or temporarily hiding sections.


What is an HTML Comment?

A comment is a note you write in the HTML that the browser does not display. It starts with <!-- and ends with -->. Anything between those markers is skipped when the page is rendered.

Developers use comments to explain what a section of code does, to leave reminders, and to temporarily switch off parts of a page during testing without deleting them.

Syntax

The comment syntax
Example
<!-- This is a comment and will not be shown -->

Example: Comments Explaining Code

Notes that describe each section
Example
<!DOCTYPE html>
<html>
<body>
  <!-- Page title -->
  <h1>My Blog</h1>

  <!-- Introduction paragraph -->
  <p>Welcome to my very first blog post.</p>

  <!-- TODO: add a sign-up form here later -->
</body>
</html>

More Examples

Hiding an element without deleting it
Example
<!DOCTYPE html>
<html>
<body>
  <p>This paragraph is visible.</p>
  <!-- <p>This paragraph is commented out and hidden.</p> -->
  <p>This paragraph is also visible.</p>
</body>
</html>
A multi-line comment
Example
<!--
  This is a longer comment.
  It can span several lines.
  Useful for describing a whole section.
-->
<h2>Section that follows the comment</h2>
⚠️

Comments are visible to anyone who views your page source. Never put passwords, secret keys, or private notes inside HTML comments.

💡

You cannot nest comments. Writing a comment inside another comment breaks at the first --> the browser finds.

Key Takeaways

  • Comments are written as <!-- note here -->.
  • The browser ignores them, so visitors never see them.
  • Use them to explain code or temporarily disable elements.
  • Never store sensitive information in comments — the source is public.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships