How to preserve line breaks when getting text from a textarea with CSS?

Spread the love

Sometimes, we want to preserve line breaks when getting text from a textarea with CSS.

In this article, we’ll look at how to preserve line breaks when getting text from a textarea with CSS.

How to preserve line breaks when getting text from a textarea with CSS?

To preserve line breaks when getting text from a textarea with CSS, we set the white-space property.

For instance, we write

textarea {
  white-space: pre-wrap;
}

to add the white-space: pre-wrap; style to make the textarea show the line breaks.

Conclusion

To preserve line breaks when getting text from a textarea with CSS, we set the white-space property.

Leave a Reply

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