- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <pre> Tag
The HTML <pre> tag is used to define a block of preformatted text that is to be presented exactly as written in the HTML file. Whitespace inside this tag is displayed as written, which means this <pre> tag preserves the text spaces, line breaks, tabs, and other formatting characters that are ignored by the browser.
If you have to display reserved characters within the <pre> tag, such as <, >, &, and ", the characters must be escape using their appropriate HTML entities (An HTML entity is a piece of text called a "string" that begins with an ampersand (&) and ends with a semicolon (;)).
The text inside the <pre> element is displayed in a fixed-width font; however, it can be changed with CSS.
Syntax
Following is the syntax of <pre> tag −
<pre>.....</pre>
Example
In the following example, we are creating an HTML document and demonstrating the usage of the <pre> tag as follows:
<!DOCTYPE html> <html> <body> <h2>Example of pre tag </h2> <pre> Hi, I am tutorialspoint, I make the things easy for the users, Users can learn here in the easy way. </pre> </body> </html>
On running the above code, the output window will pop up displaying the text used with pre tag on the webpage.
Example
Considering the another scenario, where we are going to use the pre tag.
<!DOCTYPE html> <html> <body> <figure> <pre role="img" aria-label="ASCII COW"> ___________________________ < I'm an expert in my field. > --------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || </pre> <figcaption id="cow-caption"> A cow saying, "I'm an expert in my field." The cow is illustrated using preformatted text characters. </figcaption> </figure> </body> </html>
when we run the above code, it will generate an output consisting of the data that is used in the pre tag displayed on the webpage.
Example
Let's look at the following example, where we are creating an HTML document and using the <pre> tag to write a C program, as follows −
<!DOCTYPE html> <html> <body> <pre > #include <stdio.h> int main() { int number1, number2, sum; printf("Enter two integers: "); scanf("%d %d", &number1, &number2); // calculate the sum sum = number1 + number2; printf("%d + %d = %d", number1, number2, sum); return 0; } </pre> </body> </html>
On running the above code, it will generate an output consisting of the text displaying the addition of two numbers in c program.
To Continue Learning Please Login
Login with Google