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

135 Views Asked by At

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?

2

There are 2 best solutions below

0
AudioBubble On

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.

0
Prashant Balotra On

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.