Performance: Text wrapping and overflow
This affects how text content is displayed and how the browser handles layout and repaint when text overflows or wraps.
<div class="container" style="width: 200px;"> <p class="text-break">ThisIsAReallyLongWordThatDoesNotWrapAndCausesOverflow</p> </div>
<div class="container" style="width: 200px;"> <p>ThisIsAReallyLongWordThatDoesNotWrapAndCausesOverflow</p> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Long unbroken text without wrapping | Minimal | Multiple on resize | High due to overflow repaint | [X] Bad |
| Using text-break to wrap long words | Minimal | Single initial | Low paint cost | [OK] Good |
| No wrapping with overflow visible | Minimal | Multiple on resize | High paint and scroll cost | [X] Bad |
| Using text-truncate to clip overflow | Minimal | Single initial | Low paint cost | [OK] Good |
.text-wrap to allow normal text wrapping inside containers..text-nowrap prevents wrapping, and .text-truncate truncates text with ellipsis. So, .text-wrap is the correct choice..text-nowrap is designed to stop text from wrapping onto the next line..text-wrap allows wrapping, .text-truncate truncates text, so .text-nowrap is the correct class to prevent wrapping.<div class='text-truncate' style='width: 8rem;'>This is a very long text that should be cut off.</div>
.text-truncate class in Bootstrap truncates text that overflows its container and adds an ellipsis..text-nowrap stops wrapping, and .text-truncate adds ellipsis for overflow..text-nowrap .text-truncate together prevents wrapping and truncates overflow with ellipsis..text-nowrap to prevent wrapping and .text-truncate to add ellipsis for overflow.max-width: 15rem; so truncation works. Add title attribute to show full text on hover for screen readers and keyboard users.<h5 class='text-nowrap text-truncate' style='max-width: 15rem;' title='Long title'>Long title</h5> [OK]Pass the test and this pattern moves unknown