Tutorials

KodeKite Tools

HTML
Flexbox
SVG
Canvas
HTML Tutorial

More


HTML Comments
Comments

HTML Comments are that part of code which is not visible to viewer.


  • Comments are for the facility of developers
  • Comments are used as hints in code for future understanding
  • Content or code inside comments will not display in browser

Any number of lines can be commeted by HTLM comments.

Syntax

<!--Content-->

or

<!--
Content
Content
Content
-->

Comments Types

HTML Comments can be used in two ways.


  • Single line comments
  • Multiline Comments
Single Line Comment

Single Line comment used for single line or element, mostly it is used as hints for developers to understand code in future.


Example

<!-- <p> this will not be displayed in browser </p> -->


This will be displayed in browser


Note:

Single line comment is used for only one line and you can put comments any where inside a code like you can put comments left side, inline or right side of a code.

Multiline Comment

Multiline comments are used to comment group of lines or blocks of code.


Example

<!--
<p>this will not be displayed in browser</p>
<p>this will not be displayed in browser</p>
<p>this will not be displayed in browser</p>
-->


this will be displayed in browser


You can see the output of example one and two, the commented section of code did not displyed in browser so you can use comments for your hints or guide lines in your code.


Note:

Single line comment and multiline comments have same syntax. Multiline comments are used for more than one line and you can put comments any where in your code like you can put comments top or bottom of your code.


Practice Task

Open notepad or any other text editor, follow the following points.


  • Write six paragraphs of one or maximum two lines
  • In paragraph one put single line comment left side of code
  • In paragraph two put single line comment inline of code
  • In paragraph three put single line comment right side of code
  • Now for remaining three paragraphs use multiline comments to comment all three paragraphs
  • Use <br /> element if neccessary

save file with name task.html or task.htm and then open it using any browser and see results.


Solution

I am paragraph 1

I am paragraph 2

I am paragraph 3


<!--
<p> I am paragraph 4 </p>
<p> I am paragraph 5 </p>
<p> I am paragraph 6 </p>
-->