What is HTML Preformatted Text?
In HTML, <pre>
(preformatted text) element is used to define text that preserves both spaces and line breaks within the text in a webpage.
The <pre>
element is commonly used when displaying code snippets or poems like text or any text where maintaining the original formatting, such as indentation, is important.
Please note that you should not use <pre>
for displaying regular text in a webpage.
Example of Creating HTML Preformatted Text
Create an HTML <pre>
element to your webpage.
Add your text between the <pre>
and </pre>
tags as shown in the following example.
In the following example, "Twinkle, Twinkle, Little Star", a popular English lullaby, is added to display the text format of poem with natural spaces and line breaks.
Example of Preformatted Text
Output of the above example
Twinkle, twinkle, little star How I wonder what you are Up above the world so high Like a diamond in the sky Twinkle, twinkle little star How I wonder what you are
You can display code snippets of programming languages using HTML preformatted text in a webpage.
The following example illustrates the display of code snippets of C# programming language.