Search code examples
htmlcssstylesheet

HTML Comments tags in internal stylesheet


Possible Duplicate:
Commenting out stylesheets in HTML documents to support older browsers

I am reading Professional ASP.NET 2.0 published by Wrox. see below code.

    <head>
    <style type="text/css">

    <!--

    body {
    font-family:Verdana;
    }

    -->
    </style>
 </head>

following lines are from book:

HTML comment tags are included because not all browsers support internal stylesheets.It is generally the older browsers that do not accept them. putting HTML comments around the style definitions hides these definitions from very old browsers.

now my question is that how it is possible that contents between comments hides to only old browsers not to new ones? is new browsers not get affected by comments?


Solution

  • Old (or rather, ancient) browsers do not recognise <style> so it gets treated like any other unknown element and its content is treated as HTML. The comment is treated as a comment, so nothing is rendered.

    Browsers which support <style> know to treat the content as CSS and ignore the HTML comment (as per the specification).