Last Updated : 11 Jul, 2025
The pre tag in HTML defines a block of preformatted text, preserving spaces, line breaks, and tabs. It displays text in a fixed-width font, which can be styled using CSS. This tag is useful for displaying code, formatted text, and preserving text layout.
HTML
<!DOCTYPE html>
<html>
<body>
<pre>
This is preformatted
text.
It preserves spaces and
line breaks exactly.
</pre>
</body>
</html>
The <pre> tag is a powerful tool for preserving the exact formatting of text within a web page. By using the <pre> tag, along with related tags like <samp>, <var>, <code>, and <kbd>, you can effectively display preformatted text, sample outputs, variables, code snippets, and keyboard inputs in a visually appealing and semantically meaningful way. Customizing the appearance of the <pre> element with CSS further enhances its versatility and integration into your web design.
Note: The pre
tag also supports the Event Attributes in HTML and Global Attributes in HTML.
Tag
Description
Defines sample output from a computer program
Defines a variable
Defines a piece of computer code.
Defines keyboard input
Using CSS with the <pre> Tag HTML
<!DOCTYPE html>
<html>
<body>
<pre style="font-family: Arial;color: #009900;margin: 25px;">
This is preformatted
text.
It preserves spaces and
line breaks exactly.
</pre>
</body>
</html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4