πŸŽ‰ New: Top 75 PHP Interview Questions for 2026 β€” Free for all learners
Beginner ⏱ min read πŸ”„ Updated
Home β€Ί

Advertisement

HTML Comments are used to add notes inside HTML code that are not displayed in the browser.
They help developers understand and manage code easily.

In this tutorial, you will learn how to write comments in HTML, their uses, and see examples with output.

What Are HTML Comments

HTML comments are invisible notes added in the code.

They are used to:

  • Explain code
  • Add reminders
  • Hide content temporarily

Comments are not shown in the browser output.


HTML Comment Syntax

Example

<!-- This is a comment -->

Explanation

PartDescription
<!--Start of comment
-->End of comment

HTML comments, HTML comment syntax, add comments in HTML, HTML notes, HTML basics


Simple Comment Example

Example Code

<!-- This is a heading -->
<h1>Hello HTML</h1>

Output

Hello HTML

(Comment is not visible)


Comment Inside Paragraph

Example Code

<p>This is a paragraph <!-- hidden text --> in HTML.</p>

Output

This is a paragraph in HTML.


Multi-Line Comment

HTML comments can span multiple lines.

Example Code

<!--
This is a multi-line comment
used to explain code
-->
<p>Learning HTML comments</p>

Output

Learning HTML comments


Using Comments to Hide Code

You can hide HTML code using comments.

Example Code

<!-- <p>This paragraph is hidden</p> -->
<p>This paragraph is visible</p>

Output

This paragraph is visible


Why Use HTML Comments

Benefits of Comments

BenefitDescription
Code ExplanationHelps understand code
DebuggingTemporarily hide code
Team WorkHelps other developers
OrganizationKeeps code clean

HTML Comments Summary Table

FeatureDescription
VisibleNo
Syntax<!-- comment -->
Multi-lineYes
Used forNotes and explanations

Best Practices for Comments

PracticeDescription
Keep comments clearWrite meaningful notes
Do not overuseAvoid too many comments
Update commentsKeep them relevant
Use for sectionsDivide code into parts

Common Mistakes

MistakeResult
Missing closing -->Code error
Nested commentsNot supported
Overusing commentsCluttered code
Writing important dataNot secure

HTML Comments Example with Structure

Example Code

<!DOCTYPE html>
<html>
<head>
<!-- Page title -->
<title>HTML Comments</title>
</head>
<body> <!-- Main heading -->
<h1>Welcome</h1> <!-- Paragraph -->
<p>This is a simple example.</p></body>
</html>

Output

Welcome
This is a simple example.


You may like


Frequently Asked Questions (FAQ)

1. What are HTML comments?

They are notes in HTML code that are not visible in the browser.

2. How do you write a comment in HTML?

Using <!-- comment -->.

3. Can comments hide content?

Yes, they can temporarily hide code.

4. Are comments visible to users?

No, they are hidden.

5. Can comments span multiple lines?

Yes, multi-line comments are supported.

# Summary

Here is what you've learned in this lesson:

  • What Are HTML Comments
  • HTML Comment Syntax
  • Simple Comment Example
  • Comment Inside Paragraph
  • Multi-Line Comment
  • Using Comments to Hide Code
  • Why Use HTML Comments
  • HTML Comments Summary Table
  • Best Practices for Comments
  • Common Mistakes
  • HTML Comments Example with Structure
  • You may like
  • Frequently Asked Questions (FAQ)
πŸš€
Next up: HTML Quotation and Citation Elements

Continue to the next lesson and learn more about HTML Quotation and Citation Elements.

Start Next Lesson β†’

← Previous Post
HTML Quotation and Citation Elements
Next Post β†’
CSS Tutorial