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 A live demo of this example follows. text_overflow.dart View source Open demo
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 A live demo of this example follows. text_overflow_truncate.dart View source Open demo
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 behaviour specifically.

  • text-ellipsis: Renders an ellipsis (...) when text overflows.
  • text-clip: Simply cuts off the text at the boundary.
Preview typography/text_overflow_clip A live demo of this example follows. text_overflow_clip.dart View source Open demo
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 A live demo of this example follows. text_overflow_line_clamp.dart View source Open demo
dart
WText(
  'This is a long paragraph that needs to be clamped to a specific number of lines...',
  className: 'line-clamp-3',
)

line-clamp-none and whitespace-normal cannot undo an earlier line-clamp-* / truncate; apply the clamp only where you want it (md:line-clamp-3).

Responsive Design#

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

dart
// Single line from tablet up, wrapping on mobile
WText(
  'Responsive text behaviour...',
  className: 'md:truncate',
)

// 2 lines on mobile, 4 lines on tablet and up
WText(
  'Responsive line clamping...',
  className: 'line-clamp-2 md:line-clamp-4',
)

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.