Skip to content

Add text-wrap balance and pretty to complement existing white-space utils #41491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scss/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@ $utilities: map-merge(
nowrap: nowrap,
)
),
"text-wrap": (
property: text-wrap,
class: text,
values: (
balance: balance,
pretty: pretty,
)
),
"word-wrap": (
property: word-wrap word-break,
class: text,
Expand Down
16 changes: 14 additions & 2 deletions site/src/content/docs/utilities/text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Note that we don’t provide utility classes for justified text. While, aestheti

Wrap text with a `.text-wrap` class.

<Example code={`<div class="badge text-bg-primary text-wrap" style="width: 6rem;">
This text should wrap.
<Example code={`<div class="text-wrap bg-body-secondary border" style="width: 8rem;">
This snippet of text should wrap.
</div>`} />

Prevent text from wrapping with a `.text-nowrap` class.
Expand All @@ -36,6 +36,18 @@ Prevent text from wrapping with a `.text-nowrap` class.
This text should overflow the parent.
</div>`} />

Use `.text-balance` to balance evenly distribute text across multiple lines. This is computationally expensive and is thus limited by the Chromium to six lines and by Firefox to ten lines.

<Example code={`<div class="text-balance mx-auto" style="width: 20rem;">
This text should be balanced. Here we’re writing a longer snippet of text to form a paragraph and demonstrate how the text wraps.
</div>`} />

Use `.text-pretty` to prevent single words their own line (orphans). **Pretty text wrapping is not fully supported in Safari and Firefox at the moment.**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a link to the Can I Use entry for this?
https://caniuse.com/mdn-css_properties_text-wrap_pretty


<Example code={`<div class="text-pretty mx-auto" style="width: 20rem;">
This text should be pretty. Here we’re writing a longer snippet of text to form a paragraph and demonstrate how the text wraps.
</div>`} />

## Word break

Prevent long strings of text from breaking your components’ layout by using `.text-break` to set `word-wrap: break-word` and `word-break: break-word`. We use `word-wrap` instead of the more common `overflow-wrap` for wider browser support, and add the deprecated `word-break: break-word` to avoid issues with flex containers.
Expand Down
Loading