totn HTML

HTML: <pre> tag

This HTML tutorial explains how to use the HTML element called the <pre> tag with syntax and examples.

Description

The HTML <pre> tag defines preformatted text preserving both whitespace and line breaks in the HTML document. This tag is also commonly referred to as the <pre> element.

Syntax

In HTML, the syntax for the <pre> tag is:

<body>
<pre>Text goes here    preserving whitespace
and preserving line breaks</pre>
</body>

Sample Output


Attributes

Only the Global Attributes apply to the <pre> tag. There are no attributes that are specific to the <pre> tag.

Note

  • The HTML <pre> element is found within the <body> tag.
  • The whitespace and line breaks within the <pre> tag are preserved and displayed exactly as it appears within the <pre> tag.

Browser Compatibility

The <pre> tag has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • Edge Mobile
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <pre> tag below, exploring examples of how to use the <pre> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.