Performance: Preformatted text
Using preformatted text affects the browser's layout and paint phases by preserving whitespace and line breaks, which can impact rendering speed especially with large blocks of text.
<pre>Very long preformatted text block repeated many times...</pre>
<div style="white-space: pre;">Very long preformatted text block repeated many times...</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| <div style="white-space: pre;">large text</div> | 1 node | Multiple reflows if content changes | High paint cost for large text | [X] Bad |
| <pre>large text</pre> | 1 node | Single reflow on load | Moderate paint cost, stable layout | [OK] Good |
<pre> tag do in HTML?Line 1 Line 2 indented Line 3
<pre> Hello World </pre>
Pass the test and this pattern moves unknown