👀 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>
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.
Show HTML source on a page.
Removed from HTML5.
Read old markup only.
Modern code blocks.
Editable raw text.
Display tags safely.
<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.
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.
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.
xmp may still be parsed in some environments.pre, code, or textarea in all new projects.Despite its deprecated status, here is the basic syntax of the <xmp> tag:
<xmp>
Your content here, including <tags> and &entities; which will be displayed as-is.
</xmp><xmp> tags.xmp for security or HTML escaping today.pre with escaped entities (<, >) for safe code display.| Topic | Details | Modern choice |
|---|---|---|
| Status | Obsolete / deprecated | Do not use |
| Attributes | Global only (id, class, style) | N/A |
| Display HTML source | Literal markup inside xmp | pre + code |
| Inline code | Short snippets | code |
| Editable raw text | User can change content | textarea |
| Browser support | Not recommended | Use alternatives |
<xmp> vs <pre> vs <plaintext>| Element | Purpose | Use today? |
|---|---|---|
<xmp> | Show HTML source without rendering inner tags | No — obsolete |
<pre> | Preformatted text; preserves whitespace | Yes — pair with code |
<plaintext> | Disabled all HTML parsing after the tag | No — obsolete |
<code> | Inline code fragment | Yes — semantic markup |
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 GlobalCould hook CSS selectors—prefer classes on pre or code instead.
<pre class="code-block">style GlobalInline 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.
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.
Historical xmp patterns plus modern pre, code, and textarea replacements. Legacy examples are for learning only.
Modern pre and code block (replaces xmp for showing HTML source):
<div class="container">
<p>This is a paragraph inside a div.</p>
</div>The primary use case for <xmp> was to show HTML markup as literal text on a tutorial page.
<xmp>
<div class="container">
<p>This is a paragraph inside a div.</p>
</div>
</xmp>There are several modern alternatives to the <xmp> tag that are widely supported and recommended:
The combination of <pre> and <code> is the recommended modern approach. The pre tag preserves whitespace and line breaks; code indicates programmatic content.
<pre>
<code>
<div class="container">
<p>This is a paragraph inside a div.</p>
</div>
</code>
</pre>For editable text areas that display raw HTML code, the <textarea> tag can be used.
<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>code communicates programmatic text to screen readers.label elements when users edit raw text.Tutorial pages placed sample markup inside xmp tags.
Content appeared in a fixed-width font with preserved spacing.
Standards now require pre and escaped entities for safe code display.
Modern HTML gives safe, supported ways to show HTML source on documentation pages.
Given its deprecated status, the <xmp> tag is not recommended for use in modern web development. To ensure cross-browser compatibility, use modern alternatives.
Modern browsers do not guarantee <xmp> behavior. Use pre, code, or textarea instead.
Bottom line: Do not use <xmp>. Choose pre, code, or textarea.
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.
pre and code for HTML source examples< and >textarea when users edit raw markupxmp in any new HTML documentpre or plaintext<xmp>Bookmark these so you never use obsolete code-display markup.
Not in HTML5.
StatusHistorical use case.
LegacyNo tag-specific attrs.
ReferenceModern code blocks.
AlternativeEditable raw text.
AlternativeAll modern browsers.
Compatibilityxmp 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.<pre><code>...</code></pre>. Replace < with < and > with >.textarea when users need to view or edit multi-line plain text in a form. Use pre for read-only documentation examples.id, class, and style. There are no xmp-specific attributes.Skip obsolete <xmp>. Practice pre, code, and textarea in the Try It editor.
6 people found this page helpful