HTML pre tag

The HTML

 tag
is used to specify pre formatted texts. Texts within
.......
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

Test it Now

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

Test it Now

Output:

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

If you remove pre tag from the above example, all the text will be displayed in a single line.

Output without pre:

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

width attribute

The HTML

 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. 
    

Supporting Browsers

Element chrome browser Chrome ie browser IE firefox browser Firefox opera browser Opera safari browser Safari
Yes Yes Yes Yes Yes
Next TopicHTML progress tag




Contact US

Email:[email protected]

HTML pre Tag
10/30