HTML5 <pre> Tag

The HTML <pre> tag is used to represent preformatted text. Text within this element is typically displayed in a non-proportional (“monospace”) font exactly as it is laid out in the file. Whitespace inside this element is displayed as typed.

The only content permitted inside this element is phrasing content. Both the starting and ending tag are mandatory for this element. The parent of the <pre> tag can be any element that accepts flow content.

The following style is applied to this element by default:

pre {
  display: block;
  font-family: monospace;
  white-space: pre;
  margin: 1em 0;
}

Here are some examples of using this tag:

<pre><code> body {
   color:red;
  } </code></pre>

<pre>                maxling

it is with a          heart
           heavy

that i admit loss of a feline
    so           loved

a friend lost to the
    unknown
                (night)</pre>

Attributes

This element only accepts global attributes.

Further Reading

  1. Read more about the HTML <pre> element on MDN.
  2. You can also read the HTML <pre> tag reference on W3C.

Reader Comments

1. You can register or login to post a comment. Asking readers to register improves the quality of discussion.

2. As a registered user, you will also get to access features like choosing between a light and dark theme or anything else that we might implement in future.

Follow Us For Updates

FacebookTwitterGoogle+
Go To Top