HTML Comments

By Shakib Ansari | Date: Thu, Aug 7, 2025

HTML Comments

Jab aap HTML likh rahe hote ho, toh kabhi-kabhi aapko code mein kuch notes ya temporary changes karni hoti hain jo user ko nahi dikhani hoti. Aise time par HTML Comments bahut kaam aate hain.

Chaliye simple words mein samajhte hain ki HTML Comment kya hota hai, kaise likhte hain aur kyu use karte hain.

HTML Comment Kya Hota Hai?

HTML Comment ek aisa part hota hai HTML code ka jo browser ignore karta hai. Matlab ye comment screen par dikhai nahi deta, sirf developer ke liye hota hai.

Iska use developers code ko samjhane, kisi feature ko temporarily hide karne, ya future notes ke liye karte hai.

HTML Comment ka Syntax

<!-- This is a comment -->

Example:

<!-- Navigation bar start from here -->
<nav>
 <ul>
  <li><a href="/">Home</a></li>
 </ul>
</nav>
<!-- <p> This paragraph is hidden for now. </p> -->

HTML Comments Kab Use Karne Chahiye?

1. Code Ko Explain Karne Ke Liye

Agar aapka code thoda complex hai, toh comments se aap bata sakte ho ki code ka kounsa part kis feature ko implement kar raha hai.

Example:

<!-- Header Section Start -->
<header>
  <h1>My Website</h1>
</header>

2. Code Ko Temporarily Hide Karne Ke Liye

Kabhi-kabhi developers koi element hide karna chahte hain bina usse delete kiye. Uske liye comment useful hai.

Example:

<!-- <div class="offer-banner">Special Offer!</div> -->

3. Code Ko Organize Karne Ke Liye

Aap large code files ko sections mein divide kar sakte ho:

Example:

<!-- ===== Main Content Start ===== -->
<!-- ===== Footer Section Start ===== -->

Kuch Important Points

  • Comments sirf developers ke liye hote hain, user ko page par kuch nahi dikhai deta.
  • Lekin page source mein ye visible hota hai, isliye kabhi bhi passwords ya private info comment mein nhi likhna chahiye.
  • HTML mein nested comments allow nahi hote, jaise:
<!-- Outer comment <!-- Inner comment --> -->   ❌ Wrong Statement

Real-Life Example:

<!DOCTYPE html>
<html>
<head>
  <title>My Test Page</title>
  <!-- Yahan par external CSS file link ki gayi hai -->
  <link rel="stylesheet" href="style.css">
</head>
<body>

  <!-- Website Header -->
  <header>
    <h1>Welcome!</h1>
  </header>

  <!-- Main Content -->
  <main>
    <p>Yeh site construction mein hai.</p>
    <!-- <p>Portfolio section coming soon!</p> -->
  </main>

  <!-- Footer Section -->
  <footer>
    <p>&copy; 2025 My Website</p>
  </footer>

</body>
</html>

Conclusion

HTML Comments chhoti cheez lagti hai, lekin ye aapke HTML code ko clean, understandable, aur maintainable banane mein kaafi help karti hai. Chahe aap beginner ho ya professional, comments ka smart use aapko ek better developer banata hai.

Tips:

Clear aur short comments likho

Sirf jarurat ke time hi comment karo

Sensitive information comment mein mat rakho

About the Author

Hi, I'm Shakib Ansari, Founder and CEO of BeyondMan. I'm a highly adaptive developer who quickly learns new programming languages and delivers innovative solutions with passion and precision.

Web-Development

Comments