HTML <xmp> Tag

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 3 Examples
Legacy / Obsolete

What You’ll Learn

In the early days of web development, the <xmp> tag displayed preformatted text without parsing HTML inside it. With modern HTML standards, it has been deprecated. This guide covers its history, syntax, and the supported alternatives you should use today.

01

Historical Role

Show HTML source on a page.

02

Obsolete Status

Removed from HTML5.

03

Legacy Syntax

Read old markup only.

04

pre + code

Modern code blocks.

05

textarea

Editable raw text.

06

Entity Escaping

Display tags safely.

What Is the <xmp> Tag?

The <xmp> tag was an HTML element designed to display text in a fixed-width font, preserving whitespace and showing HTML tags as literal characters instead of rendering them. It was primarily used to display HTML code snippets on tutorial pages.

⚠️
Obsolete in HTML5 — Do Not Use

The <xmp> tag is deprecated and obsolete. It is not part of current HTML standards and may behave inconsistently across browsers. Always use pre and code with escaped entities instead.

Learn xmp only to understand legacy HTML and migrate old content. For code snippets, documentation, and unformatted text today, use pre, code, or textarea.

🚫 Deprecated Status

The <xmp> tag is deprecated in HTML4 and obsolete in HTML5. This means it should not be used in modern web development because it is not supported by current standards and may not work consistently across browsers.

  • Listed as obsolete in the HTML5 specification.
  • Modern browsers may legacy-render it but behavior is unreliable.
  • HTML inside xmp may still be parsed in some environments.
  • Replace with pre, code, or textarea in all new projects.

📝 Syntax

Despite its deprecated status, here is the basic syntax of the <xmp> tag:

index.html
<xmp>
  Your content here, including <tags> and &entities; which will be displayed as-is.
</xmp>

Syntax Rules

  • Wrap content between opening and closing <xmp> tags.
  • Historically, inner HTML was shown as text rather than rendered.
  • Never rely on xmp for security or HTML escaping today.
  • Use pre with escaped entities (&lt;, &gt;) for safe code display.

⚡ Quick Reference

TopicDetailsModern choice
StatusObsolete / deprecatedDo not use
AttributesGlobal only (id, class, style)N/A
Display HTML sourceLiteral markup inside xmppre + code
Inline codeShort snippetscode
Editable raw textUser can change contenttextarea
Browser supportNot recommendedUse alternatives

⚖️ <xmp> vs <pre> vs <plaintext>

ElementPurposeUse today?
<xmp>Show HTML source without rendering inner tagsNo — obsolete
<pre>Preformatted text; preserves whitespaceYes — pair with code
<plaintext>Disabled all HTML parsing after the tagNo — obsolete
<code>Inline code fragmentYes — semantic markup

🧰 Attributes

The <xmp> tag does not support any tag-specific attributes beyond the global attributes common to all HTML elements, such as id, class, and style.

class / id Global

Could hook CSS selectors—prefer classes on pre or code instead.

<pre class="code-block">
style Global

Inline styling worked historically but external CSS on modern elements is cleaner.

font-family: monospace;

The entire <xmp> element is obsolete. No attributes make it safe or recommended for new projects.

📚 Common Use Cases

The primary historical use case for the <xmp> tag was to display HTML code snippets directly on a webpage without rendering the tags. Due to its deprecated status, it should not be used in modern web development.

Do not use xmp in new pages. Browsers no longer guarantee its behavior. Use the alternatives in the Examples Gallery below.

Examples Gallery

Historical xmp patterns plus modern pre, code, and textarea replacements. Legacy examples are for learning only.

👀 Live Preview

Modern pre and code block (replaces xmp for showing HTML source):

<div class="container">
  <p>This is a paragraph inside a div.</p>
</div>

Displaying HTML Code (Historical)

The primary use case for <xmp> was to show HTML markup as literal text on a tutorial page.

⚠️ Obsolete tag — for learning only.
index.html
<xmp>
  <div class="container">
    <p>This is a paragraph inside a div.</p>
  </div>
</xmp>
Try It Yourself

🔄 Alternatives

There are several modern alternatives to the <xmp> tag that are widely supported and recommended:

pre and code Tags

The combination of <pre> and <code> is the recommended modern approach. The pre tag preserves whitespace and line breaks; code indicates programmatic content.

index.html
<pre>
  <code>
    <div class="container">
      <p>This is a paragraph inside a div.</p>
    </div>
  </code>
</pre>
Try It Yourself

textarea Tag

For editable text areas that display raw HTML code, the <textarea> tag can be used.

index.html
<h3>HTML <textarea> Example (Alternative to <xmp>)</h3>
<textarea rows="10" cols="50">
  <div class="container">
    <p>This is a paragraph inside a div.</p>
  </div>
</textarea>
Try It Yourself

♿ Accessibility

  • Never use xmp — Obsolete markup confuses parsers and assistive technology.
  • Use semantic code elementscode communicates programmatic text to screen readers.
  • Escape HTML in examples — Use entities so assistive technology reads markup correctly.
  • Label textarea fields — Associate label elements when users edit raw text.

🧠 How <xmp> Worked (Historically)

1

Author wrapped HTML in xmp

Tutorial pages placed sample markup inside xmp tags.

Legacy
2

Browser showed monospace text

Content appeared in a fixed-width font with preserved spacing.

Rendering
3

HTML5 made xmp obsolete

Standards now require pre and escaped entities for safe code display.

Evolution
=

Use pre and code today

Modern HTML gives safe, supported ways to show HTML source on documentation pages.

Browser Support

Given its deprecated status, the <xmp> tag is not recommended for use in modern web development. To ensure cross-browser compatibility, use modern alternatives.

Obsolete · HTML5

Not supported for new development

Modern browsers do not guarantee <xmp> behavior. Use pre, code, or textarea instead.

0% Recommended use
Google Chrome Not supported
Not supported
Mozilla Firefox Not supported
Not supported
Apple Safari Not supported
Not supported
Microsoft Edge Not supported
Not supported
Internet Explorer Not supported · EOL
Not supported
Opera Not supported
Not supported
<xmp> tag 0% — obsolete

Bottom line: Do not use <xmp>. Choose pre, code, or textarea.

Conclusion

While the <xmp> tag played a role in the early days of HTML, it is now deprecated and should be avoided in favor of modern, standards-compliant tags like pre and code.

Adopting these alternatives ensures your content is accessible, maintainable, and compatible with contemporary web browsers.

💡 Best Practices

✅ Do

  • Use pre and code for HTML source examples
  • Escape angle brackets as &lt; and &gt;
  • Use textarea when users edit raw markup
  • Validate HTML to ensure standards compliance
  • Learn xmp only to read legacy tutorials

❌ Don’t

  • Use xmp in any new HTML document
  • Expect xmp to safely escape HTML today
  • Copy obsolete patterns from 1990s tutorials
  • Confuse xmp with pre or plaintext
  • Rely on browser legacy rendering for documentation

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <xmp>

Bookmark these so you never use obsolete code-display markup.

6
Core concepts
📝 02

HTML source

Historical use case.

Legacy
⚙️ 03

Global attrs

No tag-specific attrs.

Reference
📄 04

Use pre + code

Modern code blocks.

Alternative
📋 05

textarea

Editable raw text.

Alternative
🌐 06

Do Not Use

All modern browsers.

Compatibility

❓ Frequently Asked Questions

It displayed preformatted text in a fixed-width font and was used to show HTML source code on a page without rendering the inner tags.
No. The xmp tag is obsolete. Use pre and code with escaped HTML entities instead.
xmp was a legacy element for unparsed HTML display. pre is valid HTML5 and preserves whitespace when paired with escaped code content.
Wrap escaped markup in <pre><code>...</code></pre>. Replace < with &lt; and > with &gt;.
Use textarea when users need to view or edit multi-line plain text in a form. Use pre for read-only documentation examples.
Only global attributes like id, class, and style. There are no xmp-specific attributes.

Use modern code-display tags

Skip obsolete <xmp>. Practice pre, code, and textarea in the Try It editor.

Try pre + code example →

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.

6 people found this page helpful