Display Sample HTML With XMP Tags

If you want to display some sample HTML without rendering it, one old school method is to use the <xmp> </xmp> tag.

The <xmp> tag is intended to be used to display HTML examples – I’m guessing that’s where the name came from. Once the browser sees an opening <xmp>, it stops rendering all HTML until it sees a closing </xmp> tag.

Here’s a bit of sample markup to see how it would work.

<p>Here’s some sample html.</p>
<xmp>
<p>This sentence <strong>won’t</strong> be rendered.
  You should see <em>all</em> of the tags.</p>
</xmp>
<p>At this point, HTML will be rendered again.</p>

The output would look like this…

Here's some sample HTML.
<p>This sentence <strong>won’t</strong> be rendered.
  You should see <em>all</em> of the tags.</p>
At this point, HTML will be rendered again.

It’s simple and effective, but there’s one big catch: it’s a deprecated tag.

The <xmp> tag hasn’t been included in the HTML standards for some time. If you don’t care about being standards compliant, then you can go ahead and use it – chances are it might work.

However, not every browser will render the <xmp> tag correctly. I’ve heard that Opera totally ignores it, and you never know what newer browsers will do with these old tags.

You’d probably be better off with a newer, standards-compliant way to display sample HTML. One method is to use a textarea box and another method is to escape the < and > characters in your HTML.

Go back to the main guide: How to Display Sample HTML

Bookmark and Share:
  • Digg
  • Furl
  • del.icio.us
  • StumbleUpon
  • MisterWong
  • DZone
  • Technorati

One Comment to “Display Sample HTML With XMP Tags”

  1. free ebooks download said this on

    Very nice information and well laid out site with some great ebook info – just what i needed! Thanks xox

Leave a Reply