How to write Comments in HTML What is the need of Comments in HTML

Comments in HTML What is the need How to write Comments in HTML-In an HTML Document if some piece of code placed between specific Html Tags, are ignored by all web browsers. These are called Comments. Specially in complex documents it becomes necessary to write comments in your code. The purpose of the comments mostly is to indicate sections of a document. Comments are helpful also to you and others to understand the code. Some times while editing an HTML document comments prove to be very helpful because comment have no effect on the entire document. HTML Comment lines are indicated by the special starter or Opening tag <!-- and closing or the ending tag --> and any thing placed between these tags will be treated as a comment.

Comments in HTML What is the need How to write Comments in HTML

Need of writing Comments in an HTML Document

Whenever  you add a comments to an HTML document, it is always for the purpose of making it easy for another person who read it to maintain the page, or it may be helpful for yourself too after a long time.


Some times while editing a large HTML document we write some code and later we find that we do not need that code and want to remove it. To locate the code in such condition, it will be better to separate the code by comments. For example I add a code for title swapping, I can add comment as under –

<!--The code for title swapping begins here-->
Entire code here
<!--The code for title swapping ends here-->

How Comments are written in HTML Document

All comments are written between two tags, the Opening or starter Tag and the closing or the ending tag and any thing written between these tags is for understanding purpose and does not effect the entire set of code.

<!--   This is the starter or opening tag
-->    This is the closing or ending tag
<!--This is to understand only-->

In the above example the text in green is a comment and place between both the comment tags indicated in red.

HTML Comments are to be written Carefully

Some older versions of browsers may pay attention to angular brackets inside the comment and close the comment prematurely therefore a special care is required as the comment may be visible to the user,




Always make sure that there are no spaces or gap in the start of comment string otherwise your comment will be invalid. I mean to say there must be no space while writing the tag for example (Rightly written starting Tag- <!-- and wrongly written starting Tag- <  !-- -

See the following Examples -
<!--   This is a valid comment -->

The above Given comment is a valid comment in HTML though there is space between the tags but there is no space left between the tag’s characters or symbols

<  !—This is an invalid comment-->

But above line is not a valid comment and will be displayed by the browser. This is because there is a space between the left angular bracket and the exclamation mark used to write the starter tag.

Comments in HTML What is the need How to write Comments in HTML, How Comments are written in HTML Document, Need of writing Comments in an HTML Document, Valid HTML Comments and Invalid HTML Comments, comment tag, html tutorials, html comments, Basic turorial on HTML, HTML for beginners, comments in html#3 html comment, html 5, html 5 tag


1 टिप्पणियाँ

Please Donot spam

और नया पुराने