htmlxmp

Show source code without XMP tag


How do I show HTML markup including tags without using the XMP element on an HTML5 website?

The website is made with HTML5 and shows tutorials about HTML, C++ etc.

So I need to show the source code of many programming languages.


Solution

  • The most often used alternative is to use the <pre> or <code> element and escape characters that have a special meaning in HTML. < would become &lt;, > is escaped to &gt;.

    According to Can I escape html tags within a class (recreate the xmp tag)?, you can still use the XMP tag. Browsers should still support it, although according to What was the <XMP> tag used for?, <pre> is the preferred element to use.