HTML/Elements/pre

From W3C Wiki
< HTML‎ | Elements
Jump to: navigation, search

<pre>

The <pre> element represents a block of preformatted text.

Point

  • Some examples of cases:
    • e-mail
    • computer code
    • ASCII art...
  • This element is used with the <code> element, the <samp> element, or the <kbd> element, and so on, according to the kind of content inside a <pre> element. [Example B]
  • The author should consider accessibility, when use the <pre> element. This is because, when speech synthesizers, braille displays, and the like is used, there is a possibility that preformatted text is destroyed. For example, for cases like ASCII art, it is likely that a textual description or a link to avoid it would be more universally accessible to the readers of the document. More details about web accessibility and ASCII art.

HTML Attributes

See global attributes.


Examples

Example A

[try it]

<pre>
Line 1.
           Line 2 is to the right of line 1.
           Line 3 aligns with line 2.
</pre>

Pre01.png

Example B

With the code element [try it]:

<pre>
  <code>
  function Panel(element, canClose, closeHandler) {
    this.element = element;
    this.canClose = canClose;
    this.closeHandler = function () { if (closeHandler) closeHandler() };
  }
  </code>
</pre>

Pre02.png

HTML Reference

The HTML5 specification defines the <pre> element in The pre element.