Tutorials

KodeKite Tools

HTML
Flexbox
SVG
Canvas
HTML Tutorial

More


HTML Pre Element
Pre Element

In HTML <pre> element defines preserve and it does not escape extra spaces or lines, it print them in same format as were written.


  • <pre></pre> is a pair tag
  • Preserve includes new line
  • Preserve adds extra space
  • <pre> tag is a preformatted tag

Any number of spaces and lines can be added, like if you give two new lines and some extra space, it will add two lines and some extra space.

Syntax

<pre> Content </pre>


Example 1

This is paragraph


Example 2


var x=5, y=6;
var z = x + y;
document.write(z);
   


You can see the output of first and second example is same as were written in editor. <pre></pre> tag has solved many problems related to code writting, poem writting etc.


Note:

There is no need of using <br /> element for every single line while displaying code or poem in a web page.


Practice Task

Open notepad or any other text editor, follow the following points.


  • Define a paragraph.
  • The content (data) of paragraph should be I am paragraph
  • Define an other paragraph in same code.
  • The content (data) of second paragraph should be I am paragraph 2
  • Now give extra space or new line in paragraph 2.
  • Now apply preserve tag to paragraph 2.
  • Finally compare the results of both paragraphs.

save file with name task.html or task.htm and then open it using any browser and see results.


Note:

Do not use <br /> element for new line or break line, give new line by putting cursor between I am and paragraph and then press enter button and so on.


Solution

I am paragraph

    

I am paragraph 2