What exactly is CDATA and what does it do?

rhino picture rhino · Sep 28, 2010 · Viewed 9.2k times · Source

I sometimes notice a CSS or JS code surrounded with <![CDATA[ and ]]> tags. I couldn't find any explanation to this. What does CDATA do? Why is it used by some people and what is it needed for?

Answer

Philippe Carriere picture Philippe Carriere · Sep 28, 2010

It tells the interpreter that it should not try to interpret the data enclosed in the tags. For example, if you want a XML file to contain a comment with < or >, XML interpreters will report the file as invalid because the caracters < and > will not be part of standard tag. You simply have to surround the code with the CDATA tags.