What HTML element is used to display preformatted text?

The story behind the answer

The HTML element used to display preformatted text is <pre>. It preserves the text’s whitespace and line breaks, allowing content to appear much as it was written in the source document.

Browsers typically render <pre> content in a monospaced font and preserve sequences of spaces. This makes it useful for code samples, command output, ASCII art, poetry, and other text where layout matters. The element itself does not mean “program code”; for code, authors commonly place <code> inside <pre>.

A frequent mix-up is <code>, which identifies a fragment of computer code but does not by itself preserve indentation or line wrapping. <samp> represents sample output, while <blockquote> marks an extended quotation. Because the contents of <pre> are still parsed as HTML, literal angle brackets must be escaped when they are meant to appear as text.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: