What is the <pre> element in HTML?

In HTML, the <pre> element is used to display preformatted text in a fixed-width font, preserving both spaces and line breaks. <pre> displays the text in the exact format on the HTML page.

Syntax

<pre> pre-formatted content </pre>

Example

The following code demonstrates the usage of the <pre> element in HTML. The content that we want to display as preformatted text is written within the opening and closing tags, <pre> and </pre>.

  • HTML
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources