Course Progress 50%

HTML Comment Tag

HTML <!--...--> Tag को HTML Comment Tag कहा जाता है।
इस tag का उपयोग HTML code में comments लिखने के लिए किया जाता है।

Comments का मतलब होता है ऐसा text:

  • जो browser में display नहीं होता
  • लेकिन source code में दिखाई देता है
  • और developers को code समझने, explain करने या temporarily disable करने में मदद करता है

HTML comments browser द्वारा completely ignore कर दिए जाते हैं, इसलिए इनका page output पर कोई असर नहीं पड़ता।

Syntax

<!-- This is a comment -->

यह syntax browser को बताता है कि <!-- और --> के बीच लिखा गया content सिर्फ comment है।

Example Code

<p>This is a paragraph.</p>
<!-- This paragraph is used to display basic text -->

Explanation

इस example में:

  • <p> tag browser में text show करेगा
  • <!-- This paragraph is used to display basic text --> सिर्फ developers के लिए है
  • Browser इस comment को read तो करेगा, लेकिन page पर दिखाएगा नहीं

इसका result यह होगा कि user को केवल paragraph दिखाई देगा, comment नहीं।

Multiple Line Comment Example

<!-- 
This is a multi-line comment.
It can be used to explain large sections of code.
-->

Explanation

HTML comments को multiple lines में भी लिखा जा सकता है।
यह तरीका बड़े layouts या complex sections को explain करने के लिए बहुत useful होता है।

Browser इन सभी lines को ignore करता है और output पर कोई असर नहीं पड़ता।

Comment के अंदर HTML Code

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

Explanation

यहाँ <p> tag comment के अंदर है, इसलिए:

  • Browser इसे execute नहीं करेगा
  • Paragraph page पर दिखाई नहीं देगा

इस technique का उपयोग:

  • Temporary content hide करने
  • Debugging के समय code test करने
  • Layout changes check करने
    के लिए किया जाता है।

Browser Support

BrowserSupport
ChromeYes
EdgeYes
FirefoxYes
SafariYes
OperaYes

HTML comments सभी modern और old browsers में fully supported हैं।

Tips and Notes

  • HTML comments nested नहीं हो सकते
    यानी comment के अंदर दूसरा <!-- --> नहीं लिखा जा सकता

गलत example:

<!-- This is <!-- wrong --> comment -->
  • Comment के अंदर sensitive information नहीं लिखनी चाहिए
    क्योंकि page source view करने पर comments दिखाई देते हैं
  • Comments SEO को directly affect नहीं करते
    लेकिन excessive comments code readability और performance को थोड़ा प्रभावित कर सकते हैं

Standard Attributes

The comment tag does not support any standard attributes.

Event Attributes

The comment tag does not support any event attributes.

Practical Use Cases

HTML <!--...--> Tag का real-world use:

  • Code documentation के लिए
  • Team collaboration में code explanation
  • Large HTML files को readable बनाने के लिए
  • Debugging और testing के समय content temporarily disable करने के लिए

Summary

HTML <!--...--> Tag:

  • HTML code को explain करने के लिए use होता है
  • Browser में दिखाई नहीं देता
  • Beginners और advanced developers दोनों के लिए essential tool है

Clean, readable और maintainable HTML लिखने के लिए comments का सही उपयोग बहुत जरूरी होता है।