Page 54 - HTML5
P. 54

Chapter 7: Comments




        Introduction



        Similar to other programming, markup, and markdown languages, comments in HTML provide
        other developers with development specific information without affecting the user interface. Unlike
        other languages however, HTML comments can be used to specify HTML elements for Internet
        Explorer only. This topic explains how to write HTML comments, and their functional applications.


        Syntax


            •  <!-- Comment text -->


        Remarks



        Anything starting with <!-- and ending with --> is a comment. Comments cannot contain two
        adjacent dashes (--), and must end with exactly two dashes (i.e. ---> is not correct).

        Comments are not visible on a web page and cannot be styled with CSS. They can be used by the
        page's developer to make notes within the HTML, or to hide certain content during development.


        For dynamic or interactive pages, hiding and showing content is done with JavaScript and CSS
        rather than with HTML comments.


        JavaScript can be used to get the content of HTML comment nodes and these nodes can be
        dynamically created, added and removed from the document but this will not affect how the page
        is displayed.

        Since HTML comments are part of the page's source code, they are downloaded to the browser
        along with the rest of the page. The source code can typically be viewed using the web browser's
        menu option to "View Source" or "View Page Source."


        Examples



        Creating comments


        HTML comments can be used to leave notes to yourself or other developers about a specific point
        in code. They can be initiated with <!-- and concluded with -->, like so:


         <!-- I'm an HTML comment! -->


        They can be incorporated inline within other content:


         <h1>This part will be displayed <!-- while this will not be displayed -->.</h1>




        https://riptutorial.com/                                                                               38
   49   50   51   52   53   54   55   56   57   58   59