Using the PRE or XMP tag to display raw blocks of text


In creating html files, you can't just paste blocks of text into the file and have them displayed as you pasted them. There needs to be a p or br tag at the end of each line to trigger a newline when displayed in the browser. However, the xmp tag can be used to tell the browser to display the text exactly as it is formatted in the html file. Mostly I find this useful for pasting instructions from email messages into html pages like this one.

<xmp>
From the mailing list:
To fix your problem, do this:

command #1
command #2
command #3

Now your system will work and you'll have nice shiny teeth.
</xmp>
In the above example, I'm actually using <pre>, &#62 and &#60; tags for the opening xmp tag and &lt; and &gt; for the closing xmp tag, as a means of displaying the xmp tag without your browser actually interpreting it; both methods work--I'm using both so you can see two different approaches if you look at the source code for this page. The chunk of text below is actually formatted using the xmp tag. Here is a block of text, this being the first line. This is the second line of text, but I did not use a <p> or <br> tag to separate it from the first line. This is the third sentence, beginning on the fourth line because the second sentence spanned two lines. And now, after the close xmp tag, the text will display in its usual html fashion.

XMP is deprecated because it breaks some SGML rules. Instead, use <PRE> and <CODE> and use &lt; for < and &gt; for >.

03/24/2005