XHTML have various types of comments to understand the code easily, when the user dealing with the complex codes. Comments are very helpful and increase the readability of the code. Here are the various types of comments listed below.
- Comment tag
- Multiline Comments
- Comment Script Code
- Commenting Style sheets
Comment tag
XHtml also have the a comment tag which is used display the comments in browser. Whatever the content written in these comment tags is displayed on a web page as a part of an xhtml code.
The code below demonstrates the comment tag which displays the given comments in a web browser.
Internet explorer (Earlier version) do not support the comment tag and and where as supported by all other browsers. The snippet code below demonstrate the use of comment tag in html.
[html]
<!DOCTYPE html>
<html>
<head>
<title>Comment Tag</title>
</head>
<body>
<p> Simple Programming lessons <comment>(SPlessons)</comment> Tutorials </p>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.
Multiline Comments
Usually in all the documents single line of comments are used, but xhtml also supports multi lines of comments. These comments are not displayed by the web browsers which is placed in between the
< !—Multi line comments –> tags.
The code below demonstrates the Multi line comments which contains 2 or 3 lines of comments as shown below.
[html]
<!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>Content of the Document</p>
<p>XHTML</p>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.
Comment Script Code
Commenting script code means giving the comments in a script format, script code should be displayed in a web browsers but when using the script code in xhtml then it is mandatory to maintain the scripts in proper comments, so that the browsers can work properly.
The code below demonstrates the use of commenting Scripts, were script comments also displayed on web browsers like as shown.
[html]
<!DOCTYPE html>
<html>
<head>
<title>Commenting Script Code</title>
<script>
<!--
document.write("SPlessons!")
//-->
</script>
</head>
<body>
<p>Simple Programming Lessons!</p>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.
Commenting Style sheets
In order to use style sheets in commenting style sheets user need to maintain the proper codes, so that the web browser work correctly.
The code below demonstrates inserting the style sheet into the html code.
[html]
<!DOCTYPE html>
<html>
<head>
<title>Commenting Style Sheets</title>
<style>
<!--
.example {
border:2px solid #FF0040;
}
//-->
</style>
</head>
<body>
<div class="example">SPlessons</div>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.