Display element as preformatted text via CSS [duplicate]

Solution 1:

Use white-space: pre to preserve whitespace preformatting as in the pre element. To go a step further, also add font-family: monospace, as pre elements are typically set in a monospace font by default (e.g. for use with code blocks).

.preformatted {
    font-family: monospace;
    white-space: pre;
}
<div class="preformatted">

  Please procure the following items:

    - Soup
    - Jam
    - Hyphens 
    - Cantaloupe
</div>

Solution 2:

.preformatted {
   white-space: pre-wrap;
}

I think "pre-wrap" is better. It can help with long length in line.