HTML <xmp> Tag

Beginner
5 min read
Updated: Nov 2026
4 examples
Live preview

Definition and Usage

The <xmp> element once rendered the text between its start and end tags without interpreting HTML inside, typically in a monospace font. Older specs even suggested room for about 80 characters per line.

Do not use it. Prefer <pre> for blocks or <code> when the sample is computer code. Escape < and & so browsers do not treat them as markup. Related obsolete tags: <plaintext> and <listing>.

Deprecated · Obsolete.

Deprecated since HTML 3.2 and removed from current HTML. Never consistent across browsers. Avoid in every new project.

Study-only examples.

Legacy snippets exist so you can recognize old markup. Prefer the pre / code versions in real work.

HTML Syntax

syntax.html
<xmp> raw example text</xmp>

Historical form only — start and end tags, content shown as literal text. Prefer this modern equivalent:

prefer.html
<pre><code>&lt;p&gt;Hello&lt;/p&gt;</code></pre>

Attributes

<xmp> had no element-specific attributes — only globals historically. Put those attributes on modern replacements instead:

AttributeDescriptionTry it
classStyle hook (prefer on modern pre / code)Try it
idUnique target for links (prefer on modern elements)Try it
langLanguage of the text when it differs from surrounding contentTry it

Global Attributes

The <xmp> tag also supports the Global Attributes in HTML.

Live Preview

Compare a safe modern sample with a simulated historical xmp look (no live obsolete element on this page).

Prefer escaped pre/code. Legacy xmp is obsolete and inconsistently implemented.

Result
<p>Hello</p>

Modern pre + code with escaped angle brackets.

HTML Examples

Short study snippets. Use Try It Yourself for a live editor. Prefer Examples 2–4 in real projects.

Example 1 — Legacy xmp (Study Only)

Historically, content between the tags was shown without parsing inner HTML. Do not ship this.

HTML
<xmp>
<div class="box">
  <p>Shown as literal text historically.</p>
</div>
</xmp>
Try It Yourself

How It Works

  1. Open <xmp> and put the sample between the tags.
  2. Know the old rule: inner markup was meant to display as text, not run as HTML.
  3. Expect inconsistency — modern engines may not match that history.
  4. Replace immediately with pre/code and escapes.

Example 2 — pre with Escaped HTML (Preferred)

Show tags as text by escaping special characters inside <pre>.

HTML
<pre>
&lt;div class="box"&gt;
  &lt;p&gt;Hello&lt;/p&gt;
&lt;/div&gt;
</pre>
Try It Yourself

How It Works

  1. Wrap the block in <pre> to keep whitespace.
  2. Write &lt; and &gt; instead of raw < / >.
  3. Escape & as &amp; when needed.
  4. Keep the rest of the page as normal HTML after </pre>.

Example 3 — Inline code

For short snippets inside a sentence, use <code>.

HTML
<p>
  Prefer <code>&lt;pre&gt;</code> over obsolete <code>&lt;xmp&gt;</code>.
</p>
Try It Yourself

How It Works

  1. Keep prose in <p>.
  2. Wrap each token in <code>.
  3. Escape angle brackets inside the sample.
  4. Style with CSS (font-family: monospace) if you want a fixed-width look.

Example 4 — pre + code (Best Practice)

Combine both: pre for whitespace, code for semantics.

HTML
<pre><code>function hello() {
  console.log("Hi");
}</code></pre>
Try It Yourself

How It Works

  1. Open <pre> for the block.
  2. Nest <code> for computer code semantics.
  3. Paste the sample; escape < / > / & when the sample is HTML.
  4. Close both tags so the rest of the page stays normal HTML.

Edge Cases & Pitfalls

Most xmp problems come from copying historical raw-text behavior into modern pages.

obsolete

Removed from current HTML

Deprecated since HTML 3.2 and not part of modern HTML. Never build new UI on it.

escape

Escape in pre/code

To show HTML as text, use &lt;, &gt;, and &amp;. Do not rely on a raw-text element.

compat

Never consistent

Engines differed historically and may remap the element today. Treat any remaining support as accidental.

related

Also obsolete: plaintext, listing

Similar historical raw-text ideas. Prefer pre / code for all of them. See also HTML deprecated tags.

css

Monospace is a style choice

Want a fixed-width look? Use CSS font-family: monospace on a modern element — not an obsolete tag.

Browser Support

The <xmp> element is legacy HTML. It is not a Node.js, Deno, or Bun API.

✓ Deprecated · Obsolete

<xmp>

Removed from current HTML. Some browsers may still map it toward pre-like rendering. Prefer pre and code with escaped characters.

— Do not use in new work
Google Chrome Legacy
Non-standard / remapped
Mozilla Firefox Legacy
Non-standard / remapped
Apple Safari Legacy
Non-standard / remapped
Microsoft Edge Legacy
Non-standard / remapped
Opera Legacy
Non-standard / remapped
Samsung Internet Legacy
Non-standard / remapped
Internet Explorer Legacy
Historical
<xmp> Obsolete (use pre/code)

Bottom line: Recognize xmp in very old markup, then replace it with pre/code. Never ship new pages that depend on it.

Key Takeaways

  • Status: <xmp> is obsolete — avoid in new HTML.
  • History: showed content as literal text (often monospace) without parsing inner HTML.
  • Replace with: pre, code, and escaped < / &.
  • Family: also skip obsolete plaintext and listing.

One line: recognize <xmp> in old pages; show text samples with pre/code.

Default CSS Settings

There is no modern standard stylesheet for <xmp>. Engines that still remap it often behave like pre:

prefer.css
/* Prefer styling modern elements */
pre, code {
  font-family: monospace;
}

pre {
  white-space: pre;
}

Apply font-family: monospace with CSS when you want a fixed-width look — not via obsolete tags.

Frequently Asked Questions

Historically, xmp showed the text between its start and end tags without interpreting HTML inside, usually in a monospace font. It is obsolete.
No. It has been deprecated since HTML 3.2 and was removed from current HTML. Do not use it in new projects.
Use pre for preformatted blocks, or code when the sample is computer code. Escape < as &lt; and & as &amp; so browsers do not treat them as markup.
xmp wrapped content between start and end tags. plaintext historically had no end tag and treated everything after it as raw text. Both are obsolete; prefer pre/code.
Support was never consistent. Some engines may treat it like a pre-like block. Do not rely on it.
Put the sample in pre or code and escape characters: &lt; for <, &gt; for >, and &amp; for &.

Next: Deprecated tags

Browse other obsolete HTML elements and their modern replacements.

deprecated tags →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful