HTML pre tag

HTML <pre> tag prints the original text i.e. it preserves the spaces and the format of text. For instance, a poem or a coding sample.

<p>
 The text that 	we
 write inside pre   element 
 preserves       the text formatting 
 including	spaces.
 </p>
	
 <pre>
 The text that 	we
 write inside pre   element 
 preserves       the text formatting 
 including	spaces.
 </pre>

</>

The text that we write inside pre element preserves the text formatting including spaces.

 The text that 	we
 write inside pre   element 
 preserves       the text formatting 
 including	spaces.
 

Tag Uses

Specific uses of <pre> tag

to make an ASCII art (using symbols with <pre> tag)

<pre>
     *                         
    ***                                
   *****
  *******     
   ***** 
    ***
     *	
 </pre>

Try</>

to indicate the structure of computer code

 <pre><code>
  var x;
 function square(x){
 document.write(x*x*x);
 }
 square(5);
 </code></pre>
 
Try</>

Tag omission

Both opening and closing tags are necessary for the pre element.

Global Attributes

All the global attributes are applicable on the pre element.



Was this article helpful?