Question

I read that xmp tag is deprecated, but I need to output code as plain text. So is there some way how to simulate xmp tag behavior? Thanks for help.

Was it helpful?

Solution

You cannot simulate the special parsing mode of xmp elements in HTML, except in genuine XHTML (i.e., XHTML served with an XML media type), where you can use CDATA sections. The reason is that this is about low-level parsing of HTML, hard-wired into browsers.

So if you don’t want to use xmp, the only way is to “escape” the characters “&” and “<” in the content. Note that HTML5 drafts require browsers to keep supporting xmp (while declaring it as obsolete and forbidden).

OTHER TIPS

Use <pre> or <code>. From MDN:

Use the <pre> element or, if semantically adequate, the <code> element instead. Note that you will need to escape the '<' character as '<' to make sure it is not interpreted as markup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top