Preformatted Text in HTML: <pre> tag

The preformat tag instructs your web browser to display the text exactly as typed in the HTML document, including spaces, tabs, and carriage returns. A browser typically displays such text as a monospaced type. An example of the preformat tag:

code:


<pre>This is some text.
       This is some text.
           This is some text.</pre>

result:

This is some text.
      This is some text.
            This is some text.





HTML tag <pre> with CSS

code:


<!DOCTYPE html>
<html>
<head>
<style>
pre {
background-color: #eee;
color:red;
font-size:30px;
font-family: normal;
white-space: pre;
margin: 1em 10; 
}
</style>
</head>
<html>
<body>
<pre>This is some text.
       This is some text.
           This is some text.</pre>
</body>
</html>

result:

This is some text.
       This is some text.
           This is some text.




ANOTHER WAY:

Whitespace with character entities code:

&nbsp;



<p>&nbsp;This is some text.<br>
   &nbsp;&nbsp;This is some text.<br>
   &nbsp;&nbsp;&nbsp;&nbsp;This is some text.</p>

result:
This is some text.
  This is some text.
    This is some text.




Learn HTML code: preformat text (YouTube)


Privacy Policy