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

<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>
Try </>

Specific uses

Its common uses are given below.

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

Example

<pre>
     *                         
    ***                                
   *****
  *******     
   ***** 
    ***
     *	
 </pre>
Try </>
  • to indicate the structure of computer code

Example

 <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?

 

Email:

Message:

Get the newsletter