Skip to content

Text Overflow

View raw .md

Utilities for controlling how text behaves when it overflows its container.

On this page
Preview typography/text_overflow The live demo is not available for this example. text_overflow.dart View source
dart
// Basic truncation
WText(
  'Long text that should be truncated...',
  className: 'truncate',
)

// Limit to specific lines
WText(
  'Multi-line text block...',
  className: 'line-clamp-3',
)

Basic Usage#

Use truncate to prevent text from wrapping and truncate overflowing text with an ellipsis (...) if needed. This is the most common way to handle overflow for single-line text.

dart
WDiv(
  className: 'w-64',
  child: WText(
    'The quick brown fox jumps over the lazy dog.',
    className: 'truncate',
  ),
)

Quick Reference#

Class Properties Description
truncate maxLines: 1, softWrap: false, overflow: ellipsis Truncate text with an ellipsis on a single line.
text-ellipsis overflow: ellipsis Use an ellipsis for overflow.
text-clip overflow: clip Clip overflowing text (no ellipsis).
line-clamp-{n} maxLines: n, overflow: ellipsis Limit text to n lines.
line-clamp-none maxLines: null Remove line limits.

Truncate#

The truncate utility is a shorthand that sets three properties at once:

  1. Sets maxLines to 1
  2. Disables softWrap
  3. Sets overflow to TextOverflow.ellipsis
Preview typography/text_overflow_truncate The live demo is not available for this example. text_overflow_truncate.dart View source
dart
WText(
  'Long text that will be cut off with an ellipsis if it gets too long',
  className: 'truncate',
)

Ellipsis & Clip#

Use text-ellipsis or text-clip to control the visual overflow behavior specifically.

  • text-ellipsis: Renders an ellipsis (...) when text overflows.
  • text-clip: Simply cuts off the text at the boundary.
Preview typography/text_overflow_clip The live demo is not available for this example. text_overflow_clip.dart View source
dart
// Ellipsis (default for truncate/line-clamp)
WText('...', className: 'text-ellipsis')

// Clip (hard cut)
WText('...', className: 'text-clip')

Line Clamp#

Use line-clamp-{n} to limit text to a specific number of lines. This automatically sets the overflow style to ellipsis.

Supported values are any integer number (e.g., line-clamp-2, line-clamp-5) and line-clamp-none.

Preview typography/text_overflow_line_clamp The live demo is not available for this example. text_overflow_line_clamp.dart View source
dart
WText(
  'This is a long paragraph that needs to be clamped to a specific number of lines...',
  className: 'line-clamp-3',
)

// Resetting line clamp
WText(
  '...',
  className: 'line-clamp-3 lg:line-clamp-none',
)

Responsive Design#

Apply different overflow utilities at different breakpoints using standard responsive prefixes.

dart
// Truncate on mobile, allow wrapping on desktop
WText(
  'Responsive text behavior...',
  className: 'truncate md:whitespace-normal',
)

// 2 lines on mobile, 4 lines on tablet, unlimited on desktop
WText(
  'Responsive line clamping...',
  className: 'line-clamp-2 md:line-clamp-4 lg:line-clamp-none',
)

Dark Mode#

While overflow utilities don't visually change in dark mode, you can still apply them conditionally using the dark: prefix if your design requires different text handling in dark mode.

dart
WText(
  '...',
  className: 'truncate dark:line-clamp-2',
)

Arbitrary Values#

Customizing Theme#

These utilities do not use theme variables. line-clamp accepts numeric values directly, and overflow types are static.

esc

Search index did not load.

No match for "".

Try a class like rounded-lg or a widget like WButton.