Pre tag line break | Pre tag in HTML

Why we use the pre (<pre>) tag in html?

The pre tag or <pre> tag is use to display the text preformatted text in a browser. It is very useful when you are trying to show code snippet and want the code to be properly indented. It is also used to display the forced line breaks in an HTML text. To elaborate more we are show you this code.

Pre tag in Html example

 

<!DOCTYPE html>
<html lang='en'>

<head>

<meta charset="UTF-8" />

<title>

Preformatted Text Example

</title>

</head>

<body>

<p><!—change it to pre tag to get the preformatted text -->

This text is

preformatted

and should  be

displayed in a

particular way

and shape without any

reformatting

by

the

browser.

 

The

format

is the

poetry.

</p>

<pre>

int main( int argc, char ** argv ) {

printf(&quot;Hello, ilmiweb World!n&quot;);

return 0;

}

</pre>

</body>

</html>

 

Output:

This text is preformatted and should be displayed in a particular way and shape without any reformatting by the browser. The format is the poetry.

int main( int argc, char ** argv ) {

printf(“Hello, ilmiweb World!n”);

return 0;

}

If we change the <p> tag to a <pre> tag than the output will be:

Pre tag in Html example


<!DOCTYPE html>

<html lang='en'>

<head>

<meta charset="UTF-8" />

<title>

Preformatted Text Example

</title>

</head>

<body>

<pre><!—change it to pre tag to get the preformatted text -->

This text is

preformatted

and should  be

displayed in a

particular way

and shape without any

reformatting

by

the

browser.

 

The

format

is the

poetry.

</pre>

<pre>

int main( int argc, char ** argv ) {

printf(&quot;Hello, ilmiweb World!n&quot;);

return 0;

}

</pre>

</body>

</html>

Output:

          This text is
        preformatted
     and should  be
   displayed in a
     particular way
       and shape without any
         reformatting
       by
     the
   browser.

     The
       format
           is the
                poetry.
int main( int argc, char ** argv ) {
    printf("Hello, ilmiweb World!n");
    return 0;
}

As you see the <pre> tag is very useful in displaying the code properly or in its natural formating in a web page.

Comments