HTML <pre> Tag

The <pre> tag defines a preformatted text.

The text between the <pre> tags is shown in a fixed-width font (usually Courier), and it keeps both spaces and line breaks.

Syntax

The <pre> tag comes in pairs. We must write the content between opening (<pre>) and closing (</pre>) tags.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Title of the document</title>
   </head>
   <body>
      <pre>We see here a preformatted text.
All characters in this area have the same width, and spaces and line breaks within this element are shown as typed.</pre>
   </body>
</html>

Result



It is possible to use it also for writing a code.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Title of the document</title>
   </head>
   <body>
      <pre>
body {
  color:orange;
}
</pre>
   </body>
</html>

Result



Attributes

Attribute Value Description
width number Defines the maximum character number per line.
It's not supported anymore in HTML5.

The <pre> element also supports the Global Attributes.