Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there often a <!-- inside the style tag? [duplicate]

Tags:

html

css

Possible Duplicate:
What is the usage of comment notations in style tag?

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

In my knowledge this is a html comment but why is it put inside the style tag, whats the sense? Is it to exclude certain browsers which will see it as a comment?

like image 208
Chris Avatar asked Jan 01 '12 19:01

Chris


People also ask

What is the style tag used for?

The <style> tag is used to define style information (CSS) for a document. Inside the <style> element you specify how HTML elements should render in a browser.

What goes inside the style element?

The <style> HTML element contains style information for a document, or part of a document. It contains CSS, which is applied to the contents of the document containing the <style> element.

How do I remove a style tag?

If you want to remove a specific style tag, you can add a class (or id) to it and then use remove() to remove that class.

Why do we use style tag in HTML?

The <style> tag in HTML helps us to modify our text, viewed in the page. This modification includes changing font size, font family, font color etc. Not only the texts but also we can change the style of a body ar part of a page.


2 Answers

It is an HTML comment ensuring a browser will not interpret the CSS within the style element as HTML to display.

Mostly used for (very) old browsers that did not support CSS at all or did not know it ignore the content within the element.

This was also commonly done with inline javascript.

like image 170
Oded Avatar answered Oct 02 '22 19:10

Oded


"Is it to exclude certain browsers which will see it as a comment?"

Yes.

like image 24
Christian Neverdal Avatar answered Oct 02 '22 19:10

Christian Neverdal