# Preserve meaningful whitespace in a pasted log excerpt

Canonical: https://githtml.com/guides/preformatted-log-whitespace-collapses
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

Use preformatted markup or an appropriate white-space rule when spaces and line breaks carry meaning in a log excerpt. Ordinary HTML collapses many whitespace sequences. Preserve only the excerpt needed for the explanation, and choose deliberately between wrapping long lines and allowing a locally scrollable block.

## Identify the specific failure

A log copied into a paragraph can merge separate events into one sentence. Manual br elements may restore line breaks while still losing indentation. Conversely, preserving every space in a wide dump can make mobile reading impractical.

## Make a narrow correction

Use pre for genuinely preformatted material and explain the relevant lines outside it. For prose-like output where wrapping is safe, pre-wrap can retain line breaks while allowing wrapping. Do not wrap a fixed-column example without acknowledging that its alignment may change.

1. Identify which whitespace carries meaning and which is incidental formatting.
2. Choose wrapping or local scrolling according to the excerpt's structure.
3. Keep an explanatory summary outside the block so the conclusion is not hidden in dense output.

````text
pre.log { white-space: pre-wrap; overflow-wrap: anywhere; }
````

## Choose a presentation that preserves the excerpt's structure

Start by classifying the excerpt. A timestamped sequence usually needs its line boundaries, while a fixed-column diagnostic table also needs horizontal alignment. A stack trace may use indentation to show relationships. These are not interchangeable formatting requirements. Compare the plain source with the rendered block and identify exactly which spaces or newlines matter. If the original excerpt is structured data that has merely been aligned with spaces, an actual HTML table may be a better reading representation than trying to preserve a fragile visual grid.

For a fixed-column excerpt, a monospace font and preserved whitespace help maintain alignment, but a wrapped line can still be mistaken for a new record. Use local horizontal scrolling when keeping each record intact matters, and explain that the block scrolls. For prose-like output, pre-wrap can preserve explicit newlines while allowing long lines to fit. The example's overflow-wrap rule is an emergency wrapping option, not a guarantee that arbitrary technical strings remain easy to interpret. Select it according to the excerpt rather than applying it to every code block.

Check tabs and spaces separately when columns remain misaligned. Different tab rendering and font metrics can change the apparent alignment without changing the underlying text. Do not repair that by inserting more spaces until one preview looks right. Either normalize the illustrative excerpt deliberately and say it was reformatted, or preserve the source and provide an explanatory table beside it. Copy several complete lines back to plain text and verify that timestamps, identifiers, and continuation lines retain their intended relationship. Keep redaction markers conspicuous so removed values are not mistaken for empty fields.

## Verify the repaired artifact

Compare timestamps, indentation, and blank lines against the source. Check the final line, which can be easy to omit during selection.

## Sources and further reading

- [MDN: white-space](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/white-space)

## Related guides

- [Find styles accidentally restricted to print media](https://githtml.com/guides/print-media-css-screen-missing)
- [Why query-string tabs stop working in saved HTML](https://githtml.com/guides/query-string-tabs-static-html)
- [Check safe-area padding when text touches device edges](https://githtml.com/guides/safe-area-padding-html-reading)
- [Why a web component disappears from an HTML export](https://githtml.com/guides/shadow-dom-content-missing-export)

Editorial approach: https://githtml.com/guides/about
