The <pre> tag in HTML is used to display preformatted text exactly as written in the source code. It preserves spaces, line breaks, and indentation in the webpage.
- <pre> tag displays text in a preformatted style.
- It preserves spaces, tabs, and line breaks.
- It is commonly used for displaying code or formatted text.
- Text inside <pre> is usually shown in a monospace font.
<!DOCTYPE html>
<html>
<body>
<pre>
This is preformatted
text.
It preserves spaces and
line breaks exactly.
</pre>
</body>
</html>
- <pre> tag preserves the exact formatting, spaces, and line breaks of text.
- It is useful for displaying code snippets, sample outputs, and formatted text.
- Tags like <code>, <kbd>, <samp>, and <var> can be used with <pre>.
- CSS can be applied to customize the appearance of <pre> content.
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
<!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>