How do I wrap text in a 'pre' tag in HTML?


In this article we are going to learn how to wrap a text in <pre> tag in HTML. The HTML <pre> tag is used to present preformatted block of text.

Preformatted text refers to text that has already been formatted and should not be formatted further.

The <pre> tag also takes a closing tag (</pre>) like lot of other HTML elements.

Syntax

Following is the basic syntax for <pre> tag.

<pre>
   Enter text here…
</pre>

When you present a text in the webpage via <pre> tag, it is shown in the format you wrote it in the format. I.e., the spaces and indentation etc. All the settings change and show in the same form.

The most popular use of this tag is nowadays to represent a programming code. For this, this tag is used with <code>.

The programming code is represented by spaces and indentation and only then it makes sense. That is why the <pre> tag is used to represent the programming code. Now it has become a standard and everyone follows it.

Example

Following is the example program to wrap text in a <pre> tag in HTML.

<!DOCTYPE html> <html> <head><title>pre</title></head> <body> <pre> function trigger() { document.getElementById("hover") .addEventListener("mouseover",popup); function popup() { alert("Welcome to my WebPage !!!"); } } </pre> </body> </html>

Example

Following is the example program where we didn’t used a <pre> tag.

<!DOCTYPE html> <html><head><title>pre</title></head> <body> To Date: 25/Jan/2020 The principal NMA College Hyderabad Subject: "APPLICATION FOR SICK LEAVE." Sir/madam Respectfully I bag to say that I am suffering from fiver and body pain. So my doctor suggest me totally bad rest for 10 days. That is on 25/Jan/2019 to5/Feb/2019. I will think of going only if you accept my request. I will highly obliged. Thanking You Your faithfully Lokesh B 10th class </body> </html>

Example

Following is the example program to wrap text in a <pre> tag in HTML.

<!DOCTYPE html> <html><head><title>pre</title></head> <body> <pre> To Date: 25/Jan/2020 The principal NMA College Hyderabad Subject: "APPLICATION FOR SICK LEAVE." Sir/madam Respectfully I bag to say that I am suffering from fiver and body pain. So my doctor suggest me totally bad rest for 10 days. That is on 25/Jan/2019 to5/Feb/2019. I will think of going only if you accept my request. I will highly obliged. Thanking You Your faithfully Lokesh B 10th class </pre> </body> </html>

Updated on: 24-Nov-2023

719 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements