XHTML - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

XHTML Comments

XHTML Comments

shape Introduction

This chapter demonstrates about the XHTML Comments are inserted in XHTML code and the CSS. What ever the code written inside commented tags which are ignored by the browsers following are the concepts are covered in this chapter.
  • Adding Comments

Adding Comments

shape Description

XHTML comments is a comment code which are used to explain what the code does and the comments are not displayed by all the browsers and are very useful when the user dealing with lot of code. Comments does not have any Attribute values. Usually comments are placed in between the <!– …–!> tags as shown in the below image. The code below consist of comments which demonstrates about the header session, where it is starts and where it is ends. [html] <!DOCTYPE html> <html> <body> <p>Content of the document</p> <!-- This is an header section --> <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.

Various Types of Comments

shape Description

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

Summary

shape Key Points

  • Comments are very useful to understand the complex codes.
  • Nested comments are not allowed by the XHTML.
  • Multi-line comments also supported by the XHTML.