Sometimes, we want to render a string in HTML and preserve spaces and linebreaks with CSS.
In this article, we’ll look at how to render a string in HTML and preserve spaces and linebreaks with CSS.
How to render a string in HTML and preserve spaces and linebreaks with CSS?
To render a string in HTML and preserve spaces and linebreaks with CSS, we use the white-space
CSS property.
For instance, we write
div {
white-space: pre-wrap;
}
to use the white-space: pre-wrap;
style to render the whitespaces in the div.
Conclusion
To render a string in HTML and preserve spaces and linebreaks with CSS, we use the white-space
CSS property.