HTML <pre> Tag
Description
The <pre>
HTML tag, short for "preformatted text," is used to display text exactly as it appears in the HTML code, preserving spaces, line breaks, and formatting. It is typically used for displaying code snippets, poetry, ASCII art, or any content where the formatting and whitespace are essential. When text is enclosed within the <pre>
tag, browsers will render it using a monospaced font, such as Courier, which ensures that each character takes up the same amount of space. This tag is valuable for maintaining the integrity of text formatting, making it easier to showcase code examples or any content where maintaining spacing and line breaks is crucial.
Properties
- Permitted Parents
- Any element that accepts flow content
- Content
- Most inline tags and text
- Start/End Tags
- Start tag: required, End tag: required
Example
<pre>
Text in a pre element
is displayed in a fixed-width
font, and it preserves
both spaces and
line breaks
</pre>
Attributes
NoneGlobal Attributes
The <pre>
tag also supports the Global Attributes in HTML5
Event Attributes
The <pre>
tag also supports the Event Attributes in HTML5
Browser Support
The following table will show you the current browser support for the HTML <pre>
tag.
Desktop | |||||
12 | 1 | 1 | 15 | 4 |
Tablets / Mobile | |||||
18 | 4 | 14 | 3.2 | 1 | 4.4 |
Last updated by CSSPortal on: 30th March 2024