Home > Blockchain >  Can I use <pre> tag in any context I want linebreaks display?
Can I use <pre> tag in any context I want linebreaks display?

Time:09-18

I'm looking up HTML text format on MDN and I came across with the example below:

<address>
  <p>
    Chris Mills<br />
    Manchester<br />
    The Grim North<br />
    UK
  </p>

  <ul>
    <li>Tel: 01234 567 890</li>
    <li>Email: [email protected]</li>
  </ul>
</address>

So, Instead of using the <br/> tag to separate the <p> content, can I use the <pre> tag? Further than that, can I use it in any context I want some linebreaks?

CodePudding user response:

The <pre> tag cannot be used.

This is because <pre> defines if it is shown exactly like what is written in your source code, in monospace, and that it is pre-formatted text. Just like the comment above, you can use CSS white space.

CodePudding user response:

There is a CSS way you can retain literal newlines and whitespace.

white-space: pre-wrap;

enter image description here

For more information, you can refer here.

  • Related