HTML Comments:

Html comment




HTML comments are used to add notes or explanations to the source code of a webpage. They are ignored by web browsers and are not displayed to users visiting the webpage. Comments are useful for adding information about the structure and layout of a webpage, as well as notes about specific sections of code.

Why use HTML Comments?


HTML comments help both beginners and experienced web developers to easily organize their codes.

They act like sticky notes in HTML files.

There are several reasons why you might use comments in HTML:


1. Documenting code:

                                           Comments can be used to add explanations and context to the code, making it easier for others (or yourself) to understand what the code does and why it's written a certain way.


2. Temporarily disabling code:

                                                     Comments can be used to temporarily disable a section of code without having to delete it. This can be useful for testing or debugging purposes.


3. Collaboration: 

                            Comments are useful when working in a team, as they can be used to communicate ideas and issues, and to indicate who wrote which parts of the code.


4. SEO: 

              Comments in HTML can be used to hide specific information from search engines, as well as to indicate which sections of the code are relevant to SEO.


5. Maintaining the code:

                                              Comments can be used to mark the version of code or the date of last modification, which can be useful for maintaining the code over time.


Overall, comments are a useful tool for making code more readable, understandable, and maintainable


How to write HTML Comments? 


To create a comment in HTML, you use the opening tag  '<!--' and the closing tag' -->'. Anything between these tags is considered a comment and will not be rendered by the browser. 

For example:


<!-- comments go here -->


Example:


<p>

Sentences shown on browsers.

 <!-- single-line comment -->

<p>

Sentences shown on browsers.

<!-- this is a multi-line comment some phrases go here some phrases go here -->

</p>

</p>

<div> <!-- putting comments beside Sentences, HTML elements and imag

</div> <!-- putting comments beside a-->


TRY IT YOURSELF


Output:


Sentences shown on browsers.

Sentences shown on browsers.

Sentences, HTML elements and images may

appear here.


On the example given above, you have learned that you can make a single-line and multi-line of HTML comments.


And if you noticed we also put comments beside a start and end tag.


That is for us to easily recognize where a specific element starts and ends.

NOTE: 

It's important to note that HTML comments are not the same as CSS or JavaScript comments, which use different syntax. CSS comments start with /* and end with */, while JavaScript comments start with // or /* and end with */.