HTML Preformatted Text

HTML element <pre> defines a preformatted text.

Preformatted text is considered to be already formatted, so the text encapsulated within this element is displayed as is, preserving all the spaces and line breaks.

Preformatted text is displayed in a fixed-width font, usually Courier.

Let's look at an example to understand how the content of such an element is processed and displayed by web browsers.

Example

<!doctype html>
<html lang="en">
<head>
</head>
<body>
    <h1>Paragraph with extra spaces and lines - are ignored</h1>
    <hr>
    <p>
        Content of a preformatted text retains all the extra spaces and lines.
        This has                                      extra spaces.
        This has two
        
        
        empty line.
    </p>
    <hr>
    <h1>Preformatted Text with extra spaces and lines - are retained</h1>
    <hr>
    <pre>
        Content of a preformatted text retains all the extra spaces and lines.
        This has                                      extra spaces.
        This has two
        
        
        empty line.
    </pre>  
</body>
</html>

Overall

The preformatted text is used to display content as is, usually used for displaying formatted content.