HTML - Comments

  »   Basic HTML  »   HTML Tutorial - Comments into HTML codes

Comments are often used in the HTML codes. That is why it is important to be pointed out to the browser to avoid showing them.

There are many reasons we can add a comment within a html script.

  • A note or a reminder, a specification or a clarification.
  • JavaScript comments
  • An unfinished element

The comment will be placed between the "<!--" and "-->" tags. This way, we will be able to leave a note to remember at a later time what the code was for, or if something is still needed to be introduced in there.

html<!--The beginning of the code that shows a photo-->

<p>This is a paragraph in between two lines of HTML comment</p>

<!--The end of the code that shows a photo-->

Demo

This is a paragraph in between two lines of HTML comment

This is just an example of the things you can comment on, in a script. In time, you will learn that these comments are very useful for a better understanding of the code at a later date.

Any text, or characters, symbols, or anything else placed between the opening tag "<!--" and the ending tag "-->" will not be shown by the browser.

HTML - Unfinished script

Comments are very useful when you work on a script but you leave it unfinished. Putting it between the two tags (<!-- code -->) will be interpreted as a comment by the browser and therefore will not be shown.

html<!-- <input type="text" size="12" /> -- Input Field -->

When you have finished the code and you will need to show it all you will need to do is to erase the two tags and the browser will show the wanted script.

html<input type="text" size="12" />

Demo

HTML - JavaScript comments

Comments are also used in JavaScript. We will talk about this in another tutorial though, dedicated to that subject. These comments will have a different goal than the informative one though.