8. HTML Comment Tag Tutorial

First of all welcome to html Comment tag tutorial.Comment may be a piece of code that is unheeded by any browser. it’s an honest follow to feature comments into your hypertext mark-up language code, particularly in advanced documents, to point sections of a document, and the other notes to anyone staring at the code. Comments assist you et al perceive your code and will increase code readability.
HTML comments ar placed in between <!– … –> tags. So, any content placed with-in <!– … –> tags are treated as comment and can be utterly unheeded 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>
html comment tag)

Valid vs Invalid Comments

Here, the given comment may be a valid comment and can be wiped off by the browser.

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

But, following line isn’t a sound comment and can be displayed by the browser. this can be as a result of there’s an area between the left angle bracket and therefore 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>

Multi line Comments

So far we’ve seen single line comments, however hypertext mark-up language supports multi-line comments further.
You can comment multiple lines by the special starting tag <!– and finishing tag –> placed before the primary line and end of the last line as shown within the given example below.

<!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>

Conditional Comments

Conditional comments solely add net somebody (IE) on Windows however they’re unnoticed by alternative browsers. they’re supported from somebody five forward, and you’ll be able to use them to offer conditional directions to totally different versions of that is.

<!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 bump into a state of affairs wherever you’ll ought to apply totally different|a special|a unique|a distinct} sheet supported different versions of net someone, in such state of affairs conditional comments are going to be useful.

Using Comment Tag

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

Commenting Script Code

Though you’ll learn JavaScript with hypertext markup language, in an exceedingly separate tutorial, however here you want to create a note that if you’re victimization Java Script or VB Script in your hypertext markup language code then it’s suggested to place that script code within correct hypertext markup language comments so recent browsers will work properly.

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

html comment tag

Commenting Style Sheets

Though you may learn victimization vogue sheets with HTML in an exceedingly separate tutorial, however here you need to create a note that if you’re victimization Cascading sheet (CSS) in your HTML code then it’s counseled to place that sheet code within correct HTML comments so recent browsers will work properly.

<!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>

html comment tag

This was all about html comment tag.Our next article is about html image adding.Read it here HTML Image Adding tutorial.

Comments

comments