TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

HTML pre tag

HTML pre tag with examples, forms, input, text, anchor, image, heading, marquee, textarea, paragraph, title, quotes, code etc.

<< Back to HTML

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

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

Output:

package com.TheDeveloperBlog;
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.TheDeveloperBlog; 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.


Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<pre>YesYesYesYesYes
Next TopicHTML progress tag




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf