Why is there often a <! -

Possible duplicate:
What is the use of comment notation in a style tag?

I was wondering that often when writing css code inside an html document there is <!-- right after the style tag. So, for example: <style type="text/css"><!-- body { text-align: center; } --></style> <style type="text/css"><!-- body { text-align: center; } --></style>

As far as I know, this is an html comment, but why is it placed inside a style tag, what's the point? Exclude some browsers that will see this as a comment?

+6
source share
4 answers

This is an HTML comment that ensures that the browser will not interpret the CSS in the style element as displayable HTML.

It is mainly used for (very) old browsers that don’t support CSS at all or don’t know that they ignore the content inside the element.

This was also usually done with inline javascript.

+15
source

"Exclude some browsers that will see this as a comment?"

Yes.

+1
source

This is to ensure that the browser does not interpret the CSS code as HTML.

0
source

That same day, not every browser supported a style tag. Violation of browsers displays the contents of the tag on the page. Comment tags do not allow these older browsers to write the contents of the tag to the page. This is not required for approximately 10 years.

0
source

Source: https://habr.com/ru/post/904849/


All Articles