The XHTML WYSIWYG Editor For Desktop & Web Applications

pre

Definition

The pre element instructs visual Web browsers to render content in a pre-formatted fashion. Most Web browsers will render pre-formatted content in a monospace font while preserving white space (spaces, tabs and hard returns).

Example

  1. <pre>
  2. function get_random_name() {
  3. $rand_name = "";
  4. for ($i = 1; $i &lt;= 8; $i++) {
  5. $rand_name .= chr(rand(97, 122));
  6. }
  7. return $rand_name;
  8. }
  9. </pre>

Best practice

Although pre element is part of the XHTML specification, its use is not encouraged, since this element has no semantic meaning and is only used for formatting. In most cases, equivalent formatting can be achieved using semantic markup like ordered lists and CSS. For example, the following code reformulates the previous example using ordered lists.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>List example</title>
  6. <style type="text/css">
  7. ol.code-unnumbered {
  8. margin: 1em 0;
  9. padding: 3px 5px 3px 5px;
  10. font-family: courier, monospace;
  11. border:1px solid silver;
  12. }
  13. ol.code-unnumbered li {
  14. list-style-type:none;
  15. padding: 1px 5px;
  16. margin: 1px 0;
  17. background: #eeeeee;
  18. }
  19. ol.code-unnumbered li.tab1 {
  20. padding-left: 2.5em;
  21. }
  22. ol.code-unnumbered li.tab2 {
  23. padding-left: 5em;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <ol class="code-unnumbered">
  29. <li>function get_random_name() {</li>
  30. <li class="tab1">$rand_name = &quot;&quot;;</li>
  31. <li class="tab1">for ($i = 1; $i &lt;= 8; $i++) {</li>
  32. <li class="tab2">$rand_name .= chr(rand(97, 122));</li>
  33. <li class="tab1">}</li>
  34. <li class="tab1">return $rand_name;</li>
  35. <li>}</li>
  36. </ol>
  37. </body>
  38. </html>

A Web browser may render the reformulated example like this:

Screen shot of computer code formatted in monospace font and indented.

Attributes

Advanced

xml:space
This attribute indicates if white space (extra spaces, tabs) should be preserved. Possible value is preserve.

Common core attributes

class
(NameTokens) This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or set of class names. Multiple class names must be separated by white space characters. Class names are typically used to apply CSS formatting rules to an element.
id
(ID) This attribute assigns an ID to an element. This ID must be unique in a document. This ID can be used by client-side scripts (such as JavaScript) to select elements, apply CSS formatting rules, or to build relationships between elements.
title
(Text) This attribute offers advisory information. Some Web browsers will display this information as tooltips. Assistive technologies may make this information available to users as additional information about the element.

Common internationalization attributes

xml:lang
(NameToken) This attribute specifies the base language of an element's attribute values and text content.
dir

This attribute specifies the base direction of text. Possible values:

  • ltr: Left-to-right
  • rtl: Right-to-left

Common event attributes

onclick
(Script) A client-side script event that occurs when a pointing device button is clicked over an element.
ondblclick
(Script) A client-side script event that occurs when a pointing device button is double-clicked over an element.
onmousedown
(Script) A client-side script event that occurs when a pointing device button is pressed down over an element.
onmouseup
(Script) A client-side script event that occurs when a pointing device button is released over an element.
onmouseover
(Script) A client-side script event that occurs when a pointing device is moved onto an element.
onmousemove
(Script) A client-side script event that occurs when a pointing device is moved within an element.
onmouseout
(Script) A client-side script event that occurs when a pointing device is moved away from an element.
onkeypress
(Script) A client-side script event that occurs when a key is pressed down over an element then released.
onkeydown
(Script) A client-side script event that occurs when a key is pressed down over an element.
onkeyup
(Script) A client-side script event that occurs when a key is released over an element.

Common style attribute

style
(Text) This attribute specifies formatting style information for the current element. The content of this attribute is called inline CSS. The style attribute is deprecated (considered outdated), because it fuses together content and formatting.

Contains

  • Inline elements, except img, object, big, small, sub, and sup, at any depth
  • Text