Web4College

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.

Example
Try it
<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.

Example

 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)

Example
Try it
<pre>
     *                         
    ***                                
   *****
  *******     
   ***** 
    ***
     *	
 </pre>

to indicate the structure of computer code

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

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.