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


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


  • 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.


Example A

[try it]

Line 1.
           Line 2 is to the right of line 1.
           Line 3 aligns with line 2.


Example B

With the code element [try it]:

  function Panel(element, canClose, closeHandler) {
    this.element = element;
    this.canClose = canClose;
    this.closeHandler = function () { if (closeHandler) closeHandler() };


HTML Reference

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