HTML » Tags » pre

Version: 2.0, 3.2, 4.0

Compability: Explorer 4, 5 Netscape 4, 6

Syntax:
<pre> ... </pre>

The <pre> tag is used to display pre-formatted text. The output will mimic exactly how the text is rendered inside the pre element including white space, tabs, and line breaks.

This allows you to maintain the appearance of data in rows and columns, or have extra white spaces in text such as poems. Perhaps one of the most common uses of this tag is to display computer code and output.

The browser will display the text in a mono spaced font. However, you can use style sheets, including the style attribute, to effect the appearance of the text to suit your desires.

The following tags may not appear inside a pre element: big, img, object, small, sub, and sup. Therefore, images (which require an img tag) cannot appear in a pre.

The closing tag is mandatory.

Examples

Code:
<pre>
function CheckFrames()
{
var strPage, strURL
strPage = location.pathname + location.search
strURL = location.protocol + "//" + location.hostname +
"/index.asp?page=" + escape(strPage)

if ((window.name != "body") || (window.parent.name != "frameset") ||
(window.parent.parent.parent != window.parent.parent))
{
window.top.location.replace(strURL)
}
}
</pre>
Output:
 
function CheckFrames()
{	
	var strPage, strURL
	strPage = location.pathname + location.search
	strURL = location.protocol + "//" + location.hostname +
			"/index.asp?page=" + escape(strPage)

	if ((window.name != "body") || (window.parent.name != "frameset") ||
		(window.parent.parent.parent != window.parent.parent))
	{
		window.top.location.replace(strURL)
	}
}    	
Explanation:

The example is shown twice, with and without the use of style sheets. (Note that HTML does not show the extra white spaces that are present in the code.) This example is the one without the use of style sheets.

Language(s): HTML
Code:
<pre style="font-family:arial; color:red; font-size:12px;">
function CheckFrames()
{
var strPage, strURL
strPage = location.pathname + location.search
strURL = location.protocol + "//" + location.hostname +
"/index.asp?page=" + escape(strPage)

if ((window.name != "body") || (window.parent.name != "frameset") ||
(window.parent.parent.parent != window.parent.parent))
{
window.top.location.replace(strURL)
}
}
</pre>
Output:
function CheckFrames()
{	
	var strPage, strURL
	strPage = location.pathname + location.search
	strURL = location.protocol + "//" + location.hostname +
			"/index.asp?page=" + escape(strPage)

	if ((window.name != "body") || (window.parent.name != "frameset") ||
		(window.parent.parent.parent != window.parent.parent))
	{
		window.top.location.replace(strURL)
	}
}
Explanation:

This example is the one that uses style sheets.

Language(s): HTML

See Also: