What was the <XMP> tag used for?

62

9

Does anyone remember the XMP tag?

What was it used for and why was it deprecated?

GateKiller

Posted 2008-08-07T09:21:41.563

Reputation: 34 070

Answers

27

A quick Google search on W3C reveals that XMP was introduced for displaying preformatted text in HTML 3.2 and earlier. When W3C deprecated the XMP tag, it suggested using the PRE tag as a preferred alternative.

Update: http://www.w3.org/TR/REC-html32#xmp, http://www.w3.org/MarkUp/html-spec/html-spec_5.html#SEC5.5.2.1

graham.reeds

Posted 2008-08-07T09:21:41.563

Reputation: 11 953

Actually they were already marked as "obsolete" in the HTML 3.0 reference. http://www.w3.org/MarkUp/html3/html3.dtd dating 1 August 1995. Which, incidentally, also quotes the exact reason why it was deprecated (this would be the answer to the OP's second question).

– Mr Lister – 2016-01-16T09:15:07.430

pre is not an alternative xmp quotes all contained text. Great for debugging. Not secure though. Works everywhere AFAIK. – Tuntable – 2017-09-04T06:39:22.617

52

XMP and PRE differ. Content within PRE tags is formatted as follows:

  • Content is shown with a fixed font,
  • All whitespace is preserved, and
  • Each line break begins a new line.

If you want to include special characters such as <, > and & within PRE tags, they must be escaped so that they are not subject to special interpretation by the browser.

In contrast, content within XMP tags does not need to be escaped.

The only character sequence that cannot be included within XMP tags is the XMP end tag (</XMP>).

XMP is still supported by the browsers I have tested. You can try it with xmp.html. View the source to see the tags.

dadinck

Posted 2008-08-07T09:21:41.563

Reputation: 940

15

I have presented four ways of representing code. Textarea seems to be the winner. Here is my evaluation: http://dadinck.x10.mx/code_example.html

– dadinck – 2013-05-31T02:38:51.653

1Security Note: XMP is NOT an XSS protection - its only purpose is when you are creating a static HTML page by yourself and you want to show some code without escaping it... – jave.web – 2014-09-30T13:17:25.737

@dadinck, Your xml.html link links to "The web hosting account associated with this website has been temporarily suspended! ".... – Pacerier – 2015-05-24T23:45:03.310

@Pacerier Sorry. That was only temporary. It is back again. – dadinck – 2015-07-06T19:29:53.863

You forgot &lt;plaintext&gt;. Same advantages as &lt;xmp&gt; without any disadvantages apart from that everything (including any &lt;/plaintext&gt;) after the tag will be printed verbatim, including &lt;/body&gt; and &lt;/html&gt;. – Boldewyn – 2016-06-02T13:56:55.083

16

XMP does some things than PRE does not support (as a long time HTML/CSS/JavaScript author you'll just have to trust me on this, or not). I still depend on XMP, there is -NO- substitute (PRE is -not- a substitute no matter what anyone says... not even close.)

Thomas

Posted 2008-08-07T09:21:41.563

Reputation: 225

21Perhaps you could explain why PRE is not a substitute for XMP. As it stands, this is not really an answer. – Anders R. Bystrup – 2012-12-13T08:24:05.510

14&lt;xmp&gt; ignores HTML tags and entities; &lt;pre&gt; doesn't. – Álvaro González – 2013-04-19T17:46:40.157

How about &lt;textarea /&gt; as a substitute? – James Love – 2013-09-05T12:54:18.677

1How about using server-side-script escaping ? :P ..........................................................................................&lt;pre&gt;&lt;?php echo htmlspecialchars("&lt;a href='test'&gt;Test&lt;/a&gt;", ENT_QUOTES); ?&gt;&lt;/pre&gt; – jave.web – 2014-09-30T13:22:01.003

1Try debugging an XML output in browser using xmp and then pre. xmp will show the correct output. – Șerban Ghiță – 2014-12-09T15:38:53.523

2

I used <textarea>, which puts the html code into a neat box and clearly defines the code as different from the text before or after.

<textarea><b>boldtext</b><textarea>

Phil Busby

Posted 2008-08-07T09:21:41.563

Reputation: 21

2

Still works to show raw html - if you use it in script, break the start tag.

var stuff='<xmp'+'>this is shown as is<br/>hello</xmp>';
document.getElementById("x").innerHTML=stuff;
<div id="x"></div>

mplungjan

Posted 2008-08-07T09:21:41.563

Reputation: 85 993

Why the downvote? – mplungjan – 2016-07-01T14:49:15.613

2

I still use the xmp tag for debugging var_dump(); in PHP. I just can't remember to use the pre tag for some reason.

I think it doesn't really matter because if you really want to output text, you should use textarea with the readonly attribute.

Adam F

Posted 2008-08-07T09:21:41.563

Reputation: 1 559

3It's very handy for this purpose. Since var_dump() doesn't return anything you need output buffer functions to HTML-encode its output. &lt;xmp&gt; is a quick alternative to writing a wrapper function and works everywhere. – Álvaro González – 2013-04-19T17:49:15.907

1

<xmp> is used with strapdown.js in formatting markdown notation. The name strapdown combining the terms bootstrap and markdown.

<!DOCTYPE html>
<html>
  <title>Example</title>
  <xmp theme="united">
## Example

 - note one
 - note two
 - note three
  </xmp>
  <script src="http://strapdownjs.com/v/0.2/strapdown.js"></script>
</html>

noobninja

Posted 2008-08-07T09:21:41.563

Reputation: 315

1

See http://www.w3.org/Bugs/Public/show_bug.cgi?id=12235

For HTML5. it was, according to the HTML5 editor (comments 11 and 12), a very close call either way.

Alohci

Posted 2008-08-07T09:21:41.563

Reputation: 57 825