Chrome 157 joins Firefox on custom text-overflow strings, with Safari in beta
Yuki Tanaka
This one has been sitting in Firefox for fifteen years. Firefox shipped text-overflow: <string> in Firefox 9, back in 2011. Daniel Schwarz reports on CSS-Tricks that Chrome 157 has now implemented it and Safari 27.3 Beta has shipped it as well, so he expects it to reach Baseline soon. Note the word "expects". Baseline isn't declared yet, and the Safari support is still in a beta.
What it does is small and very welcome. Truncated single-line text used to end in one of two ways, ellipsis or clip. Now the value can be any string you put in quotes.
What changed
The single-value syntax takes a string in place of a keyword. Here's the example from the article, which cuts the line off with an em dash:
div {
inline-size: 170px;
white-space: nowrap;
overflow-inline: hidden;
text-overflow: "—";
}
Schwarz points to the editorial reasons you'd want something other than an ellipsis. An em dash reads as interrupted dialogue, and he lists [truncated], [sic], [snip] and [excerpt] as other common bracketed markers.
The one I'd reach for first is the empty string. text-overflow: "" truncates the overflowing characters without adding anything in their place. That sounds like clip, but the article draws the line clearly: the default text-overflow: clip can leave fractional characters hanging at the edge, while the empty string removes the overflowing characters outright. If you've ever shipped a label that ends in half a letter, this is your fix.
The rules haven't moved
A string doesn't loosen any of the old requirements. Per the source, the text still has to:
- overflow in the inline direction
- sit under
white-space: nowrap, so it stays on one line - have
overflowset to anything other thanvisible
So if your custom marker isn't showing up, check those three before you blame the browser. And for text that wraps across several lines, this isn't the tool. That job belongs to line-clamp, which Schwarz calls essentially the same thing for multi-line text, with one difference: it can only truncate the last line.
The single-value syntax also respects direction, so it behaves logically in right-to-left text without extra work.
Rough edges
Two limits from the article worth knowing before you design around this. The string isn't clickable, so you can't turn your marker into a "read more" link. And truncation isn't animatable.
You can still get a reveal-on-hover effect by moving the truncation rules behind :not(:hover), as the article shows:
div {
&:not(:hover) {
white-space: nowrap;
overflow-inline: hidden;
text-overflow: "▾";
}
}
Hover the container and the full text comes back. Keep in mind this only helps pointer users. Someone on a touchscreen or a keyboard won't trigger :hover, so the full text needs another route to them.
Where support stands
Here's the state of things according to the source:
- Single-value syntax: Firefox since version 9 (2011), Chrome 157, Safari 27.3 Beta.
- Two-value syntax: Firefox only.
The two-value form puts a string at each end of a scrollable container, inline-start first and inline-end second:
div {
overflow-inline: scroll;
text-overflow: "///" ellipsis; /* <inline-start> <inline-end> */
}
With only one engine behind it, I'd treat that one as a progressive enhancement and nothing more.
What I'm watching next
Two things. First, whether Safari's support makes it out of beta, since that is the step Schwarz is counting on for Baseline. Second, fade(). The article describes it as a future value where text-overflow: fade(1em) would start fading the line 1em from the end of the line box and fade(10%) would start 10% from the end, fully transparent by the edge either way. Nothing in the source says any browser ships it yet, so for now it's a sketch. A good one, though.
Source: CSS-Tricks (css-tricks.com)