1) What is the difference between:
a) <style> .... </style>
b) <style type="text/css"> ... </style>
2) Do i have to use <!-- --> in the css code just like in javascript? [i have seen it also in css]
Printable View
1) What is the difference between:
a) <style> .... </style>
b) <style type="text/css"> ... </style>
2) Do i have to use <!-- --> in the css code just like in javascript? [i have seen it also in css]
#1
the only difference is that you tell the browser what is inside of the <style></style> tag, and of course, if you don't include type="text/css" i don't think a html validator would accept it, because the attribute is required.
#2 personally i don't know the answer so maybe this could help a bit:
http://lachy.id.au/log/2005/05/script-comments
so it is suggested to use type="text/css" everytime i code in css?
only if you want the code to be valid and you can also use meta tag to include a css file
Code:<link href="/layout.css" rel="Stylesheet" type="text/css" />
2) no, you do not have to use HTML comments (<!-- -->). They were used back in the day to hide CSS from browsers that didn't know what CSS is. Today finding such a browser is a big task, so you don't need to have the comments there.
XHTML is a bit different though! Contents of style & script elements have been defined in such a way that content needs to be defined as CDATA and commented. Atleast if you don't want a validator to complain about non-XML contents. To do this:
Code:<style type="text/css">/*<![CDATA[*/
CSS HERE
/*]]>*/</style>
Basically this works so that XML CDATA definition prevents complaints about CSS or JavaScript code being invalid XHTML, while CSS & JavaScript comments (/* comment */) prevent the CDATA part being parsed as CSS or JavaScript code.Code:<script type="text/javascript">/*<![CDATA[*/
JAVASCRIPT HERE
/*]]>*/</script>
Ugly, but it does the job. You don't have this problem if you use external CSS and JavaScript files, as stated by Justa Lol.
thank you for the correction, i didn't know about this myself before.
thank you all for the information