How you made notes for UPSC CSE

HTML Comments



Comment is a piece of code that is ignored by any web browser. It is good practice to add comments in your HTML code especially with complex documents, to display sections of a document, and any other notes to anyone looking at the code. Comments help you and others understand your code and make the code more readable.

HTML comments are placed between <!-- ... --> day. So any content placed with -in tags are treated as a comment and completely ignored by the browser.

example

<!DOCTYPE html> <html> <head> <!-- Document Header Starts --> <title>This is document title</title> </head> <!-- Document Header Ends --> <body> <p>Document content goes here.....</p> </body> </html>

This will produce the following result, without displaying the salary given as part of the comments:

Document content goes here .....

Valid vs Invalid Comments

Comments don't nest, which means that one comment can't be put in another comment. Second of the double hyphen sequence "-" cannot appear in a comment except as part of the closing - & gt; -Day. You also need to make sure that there are no spaces in the start-of-comment string.

example

Comment given here is a valid comment and will be wiped out by the browser.

<!DOCTYPE html> <html> <head> <title>Valid Comment Example</title> </head> <body> <!-- This is valid comment --> <p>Document content goes here.....</p> </body> </html>

But the following line is not a valid comment and will be displayed by the browser. That's because there is a space between the left angle bracket bracket and the exclamation point.

<!DOCTYPE html> <html> <head> <title>Invalid Comment Example</title> </head> <body> < !-- This is not a valid comment --> <p>Document content goes here.....</p> </body> </html>

This will produce the following result:

< !-- This is not a valid comment -->

Document content goes here .....

multiline comments

So far we've seen single line comments, but HTML supports multi-line comments as well.

You can comment multiple lines through the special begin tag placed before the first line and at the end of the last line as shown in the example below.

example

<!DOCTYPE html><html> <head> <title>Multiline Comments</title> </head> <body> <!-- This is a multiline comment and it can span through as many as lines you like. --> <p>Document content goes here.....</p> </body> </html>

This will produce the following result:

Document content goes here .....

conditional comment

Conditional comments only work in Internet Explorer (IE) on Windows, but they are ignored by other browsers. They are supported from Explorer 5 and above, and you can use them to give conditional instructions to different versions of IE.

example

<!DOCTYPE html><html> <head> <title>Conditional Comments</title> <!--[if IE 6]> Special instructions for IE 6 here <![endif]--> </head> <body> <p>Document content goes here.....</p> </body> </html>

You will come across a situation where you need to apply a different stylesheet based on different versions of Internet Explorer, in such a situation conditional comments will be helpful.

Use comment tag

There are only a few browsers that support tag in order to comment on part of the HTML code.

example

<!DOCTYPE html><html> <head> <title>Using Comment Tag</title> </head> <body> <p>This is <comment>not</comment> Internet Explorer.</p> </body> </html>

If you are using IE then it will produce the following result:

This is Internet Explorer.

But if you are not using IE then it will produce the following result:

This is Internet Explorer.

commented script code

Although you will learn Javascript using HTML, in a separate tutorial, but here you need to make a note that if you are using Java Script or VB Script in your HTML then it is recommended to put the script code in HTML comments properly so that old browsers can work properly.

example

<!DOCTYPE html><html> <head> <title>Commenting Script Code</title> <script> <!-- document.write("Hello World!") //--> </script> </head> <body> <p>Hello, World!</p> </body> </html>

This will produce the following result:

Hello World!

Hello, World!

annotated style sheets

Although you will learn using Style Sheets with HTML in a separate tutorial, but here you need to make a note that if you are using Casecading Style Sheets (CSS) in your HTML then it is recommended that the Style Sheet code inside put proper HTML comments so that old browsers can work properly.

example

<!DOCTYPE html><html> <head> <title>Commenting Style Sheets</title> <style> <!-- .example { border:1px solid #4a7d49; } //--> </style> </head> <body> <div class="example">Hello , World!</div> </body> </html>

This will produce the following result: