What characters allow white-space: pre-wrap to wrap?

Viewed 144

I was surprised to find that my white-space: pre-wrap; text is wrapping at > and " characters. I thought it would only wrap at new lines, -, and after one or more spaces.

Here is a fiddle.

It wraps after ", before <. It also wraps after >, before <.

I can't find anything in the spec that says what characters allow wrapping. It only says "Lines are broken at preserved newline characters, and as necessary to fill line boxes.".

1 Answers

The same characters which cause wrapping normally will also cause wrapping with white-space: pre-wrap;, with the addition that newlines and whitespace in the text will also cause newlines and whitespace in the output.

Try removing white-space: pre-wrap; in your example and you will see that the only change is that there are no longer any blank lines. Otherwise the wrapping behaviour is the same.

See: https://drafts.csswg.org/css-text/#valdef-white-space-pre-wrap

pre-wrap: Like 'pre', this value preserves white space; but like 'normal', it allows wrapping.

For more details about when wrapping can occur normally, see: https://drafts.csswg.org/css-text/#line-breaking

Related