Path // www.yourhtmlsource.comReference → <xmp>

<xmp>


The <xmp> element (example) was used to display preformatted text, typically for showing computer code or markup examples. Unlike <pre>, the <xmp> element would display HTML tags literally without parsing them. This element was deprecated very early in HTML's history.

Clock This page was last updated on 2025-11-17



Deprecation Warning

This element is obsolete and should not be used. The <xmp> element was deprecated in HTML 3.2 (1997) and removed from HTML5. It has been obsolete for over 25 years. Use <pre> and <code> instead.

The <xmp> element had unusual parsing behavior that made it incompatible with modern HTML parsers. Because it didn't parse its content as HTML, it created inconsistencies and security concerns. The modern approach uses <pre> with proper HTML entity encoding.

Syntax

<xmp>
<html>
  <head><title>Example</title></head>
  <body>Content</body>
</html>
</xmp>

The element would display the HTML tags literally without rendering them. This behavior was unique and problematic.

Modern Alternatives

Use <pre> and <code> with proper HTML entity encoding:

Old Approach (Obsolete)

<xmp>
<p>This is a paragraph.</p>
</xmp>

Modern Approach: Escape HTML Entities

<pre><code>
&lt;p&gt;This is a paragraph.&lt;/p&gt;
</code></pre>

For Code Examples

<pre><code class="language-html">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;Hello World&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

Entity Encoding Reference

Replace special characters with HTML entities:

  • < becomes &lt;
  • > becomes &gt;
  • & becomes &amp;
  • " becomes &quot;

With Syntax Highlighting Libraries

<!-- Using highlight.js or similar -->
<link rel="stylesheet" href="highlight.css">
<script src="highlight.js"></script>

<pre><code class="language-html">
&lt;div class="example"&gt;Content&lt;/div&gt;
</code></pre>

When to Avoid

Always avoid using <xmp>. There is no valid use case for this element:

  • It has been obsolete since 1997
  • It has unpredictable parsing behavior
  • It fails HTML5 validation
  • Modern browsers may not support it correctly
  • <pre> and <code> provide proper alternatives
  • HTML entity encoding is the standard approach
  • <pre> - Modern element for preformatted text
  • <code> - For inline and block code snippets
  • <samp> - For sample output from programs
  • <kbd> - For keyboard input