Comments in HTML What is the need How to write Comments in HTML ~ SAMPATKUMARI'S Blog "PARISHKAR"

Comments in HTML What is the need How to write 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
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,

HTML Editing- How to Add New Page, in Blogger Navigation Bar


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.



3 comments:

  1. Freaky article. wat to say.. dono.. kweel.. :) in one word.

    ReplyDelete
  2. Just wanted to know if there are some more methods of writing comments in HTML other than ???

    ReplyDelete
  3. I have learned to hate all traitors, and there is no disease that I spit on more than treachery. See the link below for more info.


    #traitors
    www.ufgop.org

    ReplyDelete