HTML pre tag


The HTML <pre> tag is used to specify pre formatted texts. Texts within <pre>…….</pre> tag is displayed in a fixed-width font. Usually it is displayed in Courier font. It maintains both space and line break.

It is widely used to display language examples e.g. Java, C#, C, C++ etc because it displays the code as it is typed.

HTML pre tag example

<pre>  
This is a formatted text   
by using the HTML pre tag. It maintains  
    both space and line break.  
</pre>  

Output:

This is a formatted text 
by using the HTML pre tag. It maintains
    both space and line break.

HTML pre tag example: Java code within pre

<pre>  
package com.javatpoint;  
public class FirstJava{  
public static void main(String args[]){  
System.out.println("hello java");  
}  
}  
</pre>  

Output:

package com.javatpoint;
public class FirstJava{
public static void main(String args[]){
System.out.println("hello java");
}
}

Output without pre:package com.javatpoint; public class FirstJava{ public static void main(String args[]){ System.out.println(“hello java”); } }


width attribute

The HTML <pre> tag also supports the width attribute. The width attribute specifies the desired width of the pre-formatted text. But, it is not supported in HTML 5.


Leave a Reply

Your email address will not be published. Required fields are marked *