1. Computing

Discuss in my forum

What Is Pre-Formatted Text?

By , About.com Guide

Question: What Is Pre-Formatted Text?

You add pre-formatted text to your web pages using the PRE tag.

Answer:

It used to be very common to see web pages with blocks of pre-formatted text. Using the PRE tag to define sections of the page as formatted by the typing itself was a quick and easy way to get the text to display as you expected it to. This is because pre-formatted text is defined as text in which the structure is defined by typographic conventions rather than by the HTML.

Try the PRE tag on your website with various different spacings and carriage returns. For example, try pasting the following into your web page HTML (leave the spaces exactly as they are written):


<pre>
Twas brillig and the slithey toves
    Did gyre and gimble
        in
   the
  wabe
</pre>

Typical HTML collapses the white space in the document. This means that carriage returns, spaces, and tab characters are all collapsed to one space. If you typed the above quote into a typical HTML tag like the P tag, you would end up with one line of text:

Twas brillig and the slithey toves Did gyre and gimble in the wabe

The PRE tag leaves the whitespace characters alone. So line breaks, spaces, and tabs are all maintained in the browser. Putting the quote inside a PRE tag results in:

Twas brillig and the slithey toves
    Did gyre and gimble
        in
   the
  wabe

But the PRE tag does more than just maintain the spaces. In most browseres, it is written in a monospace font. This makes the characters in the text all equal in width. In other words, the letter i takes up as much space as the letter w. But you can change this with style sheets.

Learn more about the PRE tag.

  1. About.com
  2. Computing
  3. Web Design / HTML
  4. HTML and XHTML
  5. XHTML
  6. HTML Tags
  7. What is pre-formatted text - The pre tag - Pre-formatted text

©2013 About.com. All rights reserved.