Description

The HTML element <pre> is used to define a block of preformatted text.

The preformatted text is commonly used to preserve spaces, line breaks, tabs, and other formatting characters, which would otherwise be ignored by browsers.

The preformatted text is usually rendered and displayed on browsers in a monospaced (or a fixed-width) font, such as Courier.

However, the text style can be changed using CSS.

The below table summarizes its usage.

Usage Details
Placement It is displayed as a Block element.
Contents It can contain Inline elements and text.
Tags Both the opening and closing tags are required.
Versions HTML 3.2, 4, 4.01, 5

Syntax

Here is the basic syntax of the <pre> element.

<pre>...</pre>

Examples

Run this on IDE

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example - HTML Element pre</title>
</head>
<body>
    <pre>
        The pre
        element preserves      spaces,

            line-breaks, and tabs...
    </pre>
</body>
</html>

Attributes

The following table shows the list of supported and unsupported attributes for the <pre> element.

Attribute Type Details
Element-Specific Attributes The tag <pre> has some element-specific attributes listed in the below table.
Global Attributes Like all other HTML tags, the tag <pre> supports the HTML Global Attributes.
Event Attributes The tag <pre> also supports the HTML Event Attributes.

Here is a list of attributes that are specific to the <pre> element.

Attribute Value Required Description
width number No Obsolete
Specifies the maximum number of characters per line.

Browser Compatibility

The tag <pre> is supported in all modern browsers.

  • Google Chrome 1+
  • Internet Explorer or Edge 2+
  • Firefox 1+
  • Apple Safari 1+
  • Opera 4+

Related Links