<pre>

The <pre> element in HTML shows text while preserving whitespace and line breaks, utilizing a monospace font to keep the formatting as it appears in the source code.

pre tag

The <pre> tag in HTML is used to present text exactly as written, ensuring that spaces and line breaks remain unchanged.

Syntax

index.html
<pre>
  Preformatted text here.
  Line breaks and    spaces are preserved.
</pre>

pre Demo

The pre element
    Text in a pre element
    is displayed in a fixed-width
    font, and it preserves
    both      spaces and
    line breaks
  
index.html
<h1>The pre element</h1>
<pre>
  Text in a pre element
  is displayed in a fixed-width
  font, and it preserves
  both      spaces and
  line breaks
</pre>

Definition and Usage

The <pre> tag is designed to display preformatted text, ensuring that spacing and line breaks remain as they appear in the source code.

You may also find these related tags useful:

TagDescription
<code>Displays a section of code.
<samp>Represents output from a program.
<kbd>Indicates keyboard input.
<var>Represents a variable.

Conclusion

The <pre> tag is an essential HTML element for displaying preformatted text, preserving all spaces, tabs, and line breaks. It ensures that text appears exactly as written in the source code, making it useful for code snippets, command-line outputs, and structured text. When combined with elements like <code>, <samp>, and <kbd>, it provides better control over text formatting for technical and structured content.