HTML
 Tag


The <pre> tag in HTML is used to set preformatted text. The text in it preserves spaces and line breaks i.e. the text appears the same in the web page as it is added under the HTML code.

Let us now see an example to implement the <pre> tag −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<pre>
   This is a demo text
   and will appear
   in the same format as
   it
   is visible
   here. The pre tag displays
   the text in a fixed-width
   font. It preserves
   both spaces and
   line breaks as you can see
   here.
</pre>
</body>
</html>

Output

In the above example, we have set some text which has some unexpected space and line breaks. This is done just to show the usage of <pre> to display the text as it is −

<pre>
This is a demo text
and will appear
in the same format as
it
is visible
here. The pre tag displays
the text in a fixed-width
font. It preserves
both spaces and
line breaks as you can see
here.
</pre>

Now, since we have used the <pre> tag, the above text will get displayed as it is on the web page by preserving the space and line breaks.

Updated on: 11-Jun-2020

245 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements