Just as for pre
, you can style xmp
so that it is not really preformatted but lines wrap at spaces or other permitted line break points as needed, by setting
xmp {white-space: pre-wrap }
However, this makes a line break so that the second part starts at the very left, not with the same (or larger) indentation as the first part. This makes the code look messy.
Also note that line wrapping as implemented in browsers may turn the text invalid as HTML markup. For example, many browsers feel free to break after a hyphen, but e.g. an HTML attribute like data-filter
must not be broken. Of course it would be just a matter of markup that the user sees, but still.
To create intelligent wrapping (as in many text editors and programming environments), you would need JavaScript or a more complicated setup where each line is an element of its own, indented using left margin in CSS, not with spaces.