Auralinna.blog Tero Auralinna's blog about intriguing world of web development. Tweaking pixels since the '90s.

Wrapping newlines via CSS

Published on November 30, 2017. Edited on July 5, 2020.

This is a simple tip on how to wrap newlines without converting newlines to <br> tags. This is quite handy if you have a text without formatting and the only need is to wrap text paragraphs. You don't have to think about HTML sanitization or conversion.

.wrapped-text {
    white-space: pre-line;
}

This trims newlines from the start and end of the text. Value pre-line doesn't render whitespaces in the middle of the text.