Skip to main content

Helpers

Text truncation

Cut long text with an ellipsis on block and inline-block elements.

How it works

.text-truncate sets white-space: nowrap, overflow: hidden and text-overflow: ellipsis. It only works on elements that are display: block or display: inline-block and have a constrained width. Inline text, flex items without min-width: 0, and table cells with width: auto will not truncate.

This text is quite long, and will be truncated once displayed.
This text is quite long, and will be truncated once displayed.
HTML
<!-- Block level -->
<div class="row">
  <div class="col-2 text-truncate">
    This text is quite long, and will be truncated once displayed.
  </div>
</div>

<!-- Inline level -->
<span class="d-inline-block text-truncate mt-3" style="max-width: 150px">
  This text is quite long, and will be truncated once displayed.
</span>

In components

A list of match names in a narrow sidebar is the usual case.

  • Two-out-of-three falls, 60-minute time limit, no disqualifications
  • Tag team title match — champions must defend or forfeit
  • Short one
HTML
<ul class="list-group" style="max-width: 16rem">
  <li class="list-group-item text-truncate">Two-out-of-three falls, 60-minute time limit, no disqualifications</li>
  <li class="list-group-item text-truncate">Tag team title match — champions must defend or forfeit</li>
  <li class="list-group-item text-truncate">Short one</li>
</ul>

In a flex row, the truncating item needs .min-w-0-style behaviour. The theme has no such utility; use .overflow-hidden on the flex child, or .text-truncate plus .flex-grow-1 with an explicit width.

LIVE Tonight's main event has a title that goes on forever and ever
HTML
<div class="hstack gap-3" style="max-width: 24rem">
  <span class="badge text-bg-gold">LIVE</span>
  <span class="text-truncate flex-grow-1" style="width: 0">Tonight's main event has a title that goes on forever and ever</span>
  <button type="button" class="btn btn-sm btn-outline-secondary">Watch</button>
</div>
Truncated text is still in the DOM, but sighted users cannot read it. Put the full text in a title attribute or a tooltip if it matters, and never truncate the only label on a control.

CSS

.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

Sass: @include text-truncate; applies the same three declarations in your own rules.