HTML Pre tag

 Pre Tag


The one exception to this rule is the preformatted text tag <pre>. Any whitespace that you put into text surrounded by the <pre> and </pre> tags is retained in the final output. With these tags, the spacing in the text in the HTML source is preserved when it's displayed on the page. 

Usage

The <pre> tag is also excellent for converting files that were originally in some sort of text-only form, such as email messages, into HTML quickly and easily. Just surround the entire content of the message within <pre> tags and you have instant HTML. Text within this element is typically displayed in a non-proportional font exactly as it is laid out in the file.
  • Used to display spaces, tabs, line, breaks, etc.

👉Example - 1

<!DOCTYPE html>
<html>
<head>
<title> HTML Pre Tag </title>
</head>
<body>
<pre>
Spaces            and
line         breaks        within
       this              element
as                   shown            as 
         typed.
</pre>
</body>
</html>

👉Example - 2

<!DOCTYPE html>
<html>
<head>
<title> HTML Pre Tag </title>
</head>
<body>
<pre>
#include<stdio.h>
int main(){
int n;
printf("Enter a number: ");
scanf("%d", &n);
if(n % 2 == 0){
    printf("Number is even");
}else{
    printf("Number is odd");
}
return 0;
</pre>
</body>
</html>

👉Example - 3

<!DOCTYPE html>
<html>
<head>
<title> HTML Pre Tag </title>
</head>
<body>
<pre>
Son : Well, father, air pollution is causing a great damage to modern life. But what's the way out?
Father : I think, large scale plantation of trees can solve this problem to a great extent.
Son : How can plants and trees help us overcome this problem?
Father : They absorb the poisonous carbon-monoxide from air and thus maintain balance in the atmosphere. Besides, they are important for other reasons as well.
</pre>
</body>
</html>

NOTES.....

Be careful with tabs in preformatted text. You should convert any tabs in your preformatted text to spaces so that your formatting isn't messed up if it's viewed with different tab settings than in the program you used to entire the text.
Previous Post Next Post