Reputation: 6790
How can I display <!CDATA[
as text in an html document? I tried wrapping it in <pre>
tags but that didn't work.
<! DOCTYPE html >
<html>
<body>
<div>This should show <pre><!CDATA[</pre> when the page renders</div>
</body>
</html>
Upvotes: 0
Views: 2716
Reputation: 201828
As others have written, you should escape “<” as <
. HTML markup like pre
or code
does not change the way content is parsed, with “<” as markup-significant. You can use e.g. code
markup here, since the content is computer code and this markup may have some advantages, but that’s a different issue. Example: <code><!CDATA[</code>
.
There is a half-secret markup, however: <xmp><!CDATA[</xmp>
. Within an xmp
element, everything is taken literally; only the end tag of this element is recognized. Such markup is regarded as very obsolete by many, and it has been dropped from HTML specs, but it actually keeps working.
Upvotes: 2
Reputation: 944246
Browsers do not support CDATA markers in text/html
documents. Use character references instead (<
, &
, etc).
Upvotes: 4