How to preserve line breaks in textarea with CSS?

Spread the love

Sometimes, we want to preserve line breaks in textarea with CSS.

In this article, we’ll look at how to preserve line breaks in textarea with CSS.

How to preserve line breaks in textarea with CSS?

To preserve line breaks in textarea with CSS, we set the white-space and overflow-wrap properties.

For instance, we write

textarea {
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

to add white-space: pre-wrap; to make the content wrap.

And we break the words when the overflow with overflow-wrap: break-word;.

Conclusion

To preserve line breaks in textarea with CSS, we set the white-space and overflow-wrap properties.

Leave a Reply

Your email address will not be published. Required fields are marked *