HTML <pre>
Tag
Topic: HTML5 Tags ReferencePrev|Next
Description
The <pre>
tag defines a block of preformatted text. This element is commonly used to preserves spaces, line breaks, tabs, and other formatting characters in source markup that web browsers would otherwise ignore.
Text within the <pre>
element is typically rendered by the browsers in a monospace (fixed-width) font, such as Courier, but this style can be overridden using CSS.
The following table summarizes the usages context and the version history of this tag.
Placement: | Block |
---|---|
Content: | Most inline tags and text |
Start/End Tag: | Start tag: required, End tag: required |
Version: | HTML 3.2, 4, 4.01, 5 |
Note: By default, only the first space is honored; subsequent spaces — unless specified using the
entity — aren't rendered by the browsers.
Syntax
The basic syntax of the <pre>
tag is given with:
The example below shows the <pre>
tag in action.
Example
Try this code »<pre>
The pre
element preserves spaces,
line-breaks, tabs...
</pre>
Tag-Specific Attributes
The following table shows the attributes that are specific to the <pre>
tag.
Attribute | Value | Description |
---|---|---|
width |
number | Obsolete Specifies the maximum number of characters per line. |
Global Attributes
Like all other HTML tags, the <pre>
tag supports the global attributes in HTML5.
Event Attributes
The <pre>
tag also supports the event attributes in HTML5.
Browser Compatibility
The <pre>
tag is supported in all major modern browsers.
Basic Support—
|
Further Reading
See tutorial on: HTML Text Formatting.
See CSS property: white-space.