
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- 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 Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- 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 - Document Object Model (DOM)
- 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 Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character 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 pre-formatted text that is displayed exactly as written in the HTML code. White-space within this tag is shown as it is, preserving spaces, line breaks, tabs, and other formatting characters.
If you have to display reserved characters within the <pre> tag, such as <, >, &, and ", you must escape using their appropriate HTML entities. An HTML entity is a piece of text that begins with an ampersand (&) and ends with a semicolon (;)). The text inside the <pre> element is displayed in a fixed-width font; but this can be changed with CSS.
Syntax
Following is the syntax of <pre> tag −
<pre>.....</pre>
Attributes
The HTML <pre> tag supports both Global and Event attributes. Additionally, it has some specific attributes, which are listed bellow.
Attribute | Value | Description |
---|---|---|
cols | number | Used to specify the visible width of the <pre> element. |
width | number(pixles) | Use to specify the width of the element. |
wrap | soft hard |
It specify how the text will be wrapped: either soft or hard. |
Example: Preformatted Paragraphs
In the following example, we create an HTML document to demonstrate the usage of the <pre> tag. Running the code will display the text within the <pre> tag on the webpage.
<!DOCTYPE html> <html> <body> <h2>Simply Easy Learning</h2> <pre> Hi, Welcome to tutorialspoint, we make things easy for the users, Users can learn here in the easy way. </pre> </body> </html>
Example: ASCII Art
Here, we will use the <pre> tag to render ASCII art. The HTML code displays preformatted ASCII art text, preserving spaces and breaks.
<!DOCTYPE html> <html> <body> <pre> _____ _ _ _ _ _ |_ _| _| |_ ___ _ __(_) __ _| |___ _ __ ___ (_)_ __ | |_ | || | | | __/ _ \| '__| |/ _` | / __| '_ \ / _ \| | '_ \| __| | || |_| | || (_) | | | | (_| | \__ \ |_) | (_) | | | | | |_ |_| \__,_|\__\___/|_| |_|\__,_|_|___/ .__/ \___/|_|_| |_|\__| |_| </pre> </body> </html>
Example: Displaying Different Language
Let's consider the following example, where we create an HTML document and use the <pre> tag to write a C program.
<!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>
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
pre | Yes | Yes | Yes | Yes | Yes |