Languages

HTML - how to display newline characters located in the text in the source code?

6 points
Asked by:
sienko
743

Is it posiible to display newline characters, in text on my webpage, that are located in my HTML source code?

My source code:

 

Currently, my webpage displays the text:

I want to get:

1 answer
1 points
Answered by:
sienko
743

In HTML you can use <br /> elements.

// ONLINE-RUNNER:browser;

<article class="message">
  <div class="item">
    <header></header>
    <div class="text">1<br />2<br />3<br />4<br />5<br />6</div>
  </div>
</article>

 

In CSS, you can use one of the:

  1. white-space: pre;
  2. white-space: pre-line;
  3. white-space: pre-wrap;

Example:

// ONLINE-RUNNER:browser;

<article class="message">
  <div class="item">
    <header></header>
    <div class="text" style="white-space: pre-line">1
2
3
4
5
6</div>
  </div>
</article>

 

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join