Skip to content

CSS: truncate ​

.--truncate — Ellipsis truncation with line clamping controlled by --lines — usable bare or chained onto any component (.instui-button.--truncate).

The base class uses display: -webkit-box and reads the --lines custom property to clamp text to a fixed number of lines before it ends in an ellipsis.

Source: index.ts

TIP

JS Requirement — This component ships no CSS of its own — its markup and behavior come entirely from @pantoken/interactions. Its --max-lines-auto modifier is driven by that behavior. See the modifier table below.

Usage ​

css
@import "@pantoken/components/utilities.css";

Modifiers ​

ModifierDescription
.--lines-1Alias of --max-lines-1.
.--lines-2Alias of --max-lines-2.
.--lines-3Alias of --max-lines-3.
.--lines-4Alias of --max-lines-4.
.--lines-5Alias of --max-lines-5.
.--max-lines-1Clamp to one line (default).
.--max-lines-2Clamp to two lines.
.--max-lines-3Clamp to three lines.
.--max-lines-4Clamp to four lines.
.--max-lines-5Clamp to five lines.
.--max-lines-autoInteraction — — Clamp to the number of lines that fit in the container, based on its height and the line height of the text.
.--truncateEnables truncation and line clamping on the target element.
.--truncate-character(default) Truncate at the character level.
.--truncate-wordTruncate at the word level.

Custom properties ​

PropertyTypeDefaultDescription
--ellipsisclip | ellipsis | <string> | fadeellipsis—
--lines<integer>1—

Accessibility ​

Truncation hides overflowing text visually while it stays in the DOM, so don't clip information people need (titles, errors, instructions) and keep the full text available another way. Check that clipped text still reads correctly when zoomed or resized.

ConditionsRebrand (light)Rebrand (dark)CanvasCanvas High Contrast
reflow-at-320pxWCAG 2.2 1.4.10PassPassPassPass
text-spacing-no-clippingWCAG 2.2 1.4.12FailFailFailFail

With line height 1.5, letter spacing 0.12em, word spacing 0.16em, and paragraph spacing 2em, text in one element gets cut off: p.--truncate ("Quarterly planning notes for t"). Overlapping text isn't checked.

Screen reader (simulated)Rebrand (light)Rebrand (dark)CanvasCanvas High Contrast
AnnouncementsPassPassPassPass

These automated results do not establish that the page meets WCAG; manual review is still needed.

Tokens consumed ​

TokenTypeValue
--instui-component-truncate-text-font-family[ <font-family-name> | <generic-font-family> ]#Atkinson Hyperlegible Next, "Helvetica Neue", Helvetica, Arial, sans-serif
--instui-line-height-paragraph-base<percentage>150%

Browser support ​

  • Clamping relies on -webkit-line-clamp with display: -webkit-box, paired with the standard line-clamp.
  • text — Body typography that this truncates.