SEARCH HERE

Tuesday, February 3, 2026

📘 DAY 10: HTML COMMENTS

📘 DAY 10: HTML COMMENTS 


1️⃣ What are HTML Comments?

HTML comments are used to:

  • Add notes inside HTML code

  • Explain code for developers

  • Temporarily disable code

👉 Comments are not displayed in the browser.


2️⃣ HTML Comment Syntax

HTML comments are written using:

<!-- This is a comment -->

Anything inside <!-- --> is ignored by the browser.


3️⃣ Simple Example

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

Output in browser:

Welcome Hello HTML

👉 Comments are invisible to users.


4️⃣ Multi-line Comments

HTML supports multi-line comments.

<!-- This is a multi-line comment. Used to explain large code blocks. -->

5️⃣ Commenting Out HTML Code

Comments are often used to disable code temporarily.

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

👉 The paragraph will not appear in the browser.


6️⃣ Why Use HTML Comments?

HTML comments are useful for:
✔ Understanding code
✔ Debugging
✔ Team collaboration
✔ Organizing large HTML files


7️⃣ Comments for Section Marking

<!-- Header Section --> <header> <h1>My Website</h1> </header> <!-- Main Content --> <main> <p>Content here</p> </main>

👉 Makes code clean & readable


8️⃣ HTML Comments and Security

⚠️ Comments are visible in page source
(Right click → View Page Source)

❌ Do NOT write:

  • Passwords

  • API keys

  • Confidential information


9️⃣ Invalid HTML Comment (Wrong)

❌ This will cause issues:

<!---- This is wrong --->

❌ Nested comments:

<!-- Comment <!-- nested --> -->

🔟 Correct HTML Comment Rules

✔ Start with <!--
✔ End with -->
✔ No nested comments
✔ No sensitive data


1️⃣1️⃣ Common Beginner Mistakes

❌ Forgetting closing -->
❌ Writing comments inside tags
❌ Expecting comments to show output
❌ Using comments for styling


1️⃣2️⃣ Comments vs Text

CommentText
Not visibleVisible
For developersFor users
Ignored by browserRendered

1️⃣3️⃣ Practice Example

<!-- Page Title --> <h1>HTML Comments</h1> <!-- Description --> <p>This page explains comments.</p>

1️⃣4️⃣ Interview / Viva Questions

  1. What are HTML comments?

  2. What is the syntax of HTML comments?

  3. Are comments visible to users?

  4. Can we write multi-line comments?

  5. Why should we avoid sensitive data in comments?


1️⃣5️⃣ Summary

  • HTML comments explain code

  • Not displayed in browser

  • Used for debugging & readability

  • Follow proper syntax

  • Avoid sensitive data




https://www.simplilearn.com/ice9/free_resources_article_thumb/single_line_comment-html_comments.PNG

0 comments:

Post a Comment

C++

AJAVA

C

E-RESOURCES

LKG, UKG Live Worksheets

Top