"truncate" utility cuts off characters on y-axis
Describe your issue
During development I noticed that the "g" in one of my spans was cut-off, since I was using the "truncate" utility.
From the docs we can see that it currently is bundling these classes:
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
I would argue that this is unintended behaviour and recommend switching to:
overflow-x: clip;
text-overflow: ellipsis;
white-space: nowrap;
If that is deemed too dangerous (since it might affect text written in languages that go top to bottom), maybe another utility (e.g. truncate-x or truncate-text) could be introduced.
Happy for your feedback!
It's a pity you didn't provide a reproduction. By the way, I'd like to note that this issue tends to appear with increasingly larger font sizes and is caused by a low line-height.
- https://play.tailwindcss.com/JOr2PbtKWc?size=540x720
The default line-height associated with font sizes is 1. However, you can manually override it:
- https://play.tailwindcss.com/UiCsZUQNHN?size=540x720
And you can also manually override the truncate utility:
- https://play.tailwindcss.com/xtnq1opJXJ?size=540x720&file=css (In this case, due to the original truncate, the overflow-y needs to be reset.)
Or you can introduce the desired truncate-x utility:
- https://play.tailwindcss.com/ofMmFRnW1N?size=540x720
Sorry, here is a minimal reproduction: https://play.tailwindcss.com/SxhGOlydDC?size=540x720 (replace truncate-x by truncate to see the issue)
You are correct, that it is a line-height issue, although in this specific case it is intentional.
Based on you answer, I believe its best to only introduce it in my codebase and not add it to tailwind itself. Do you think so as well?
The same problem happens when using the new text-box attribute, e.g. text-box: trim-both cap alphabetic: https://play.tailwindcss.com/0jyVQLCtZQ?size=540x720
In that case a larger line-height is exactly not what the designer wants.
So I also think tailwind should switch from overflow: hidden to overflow-x: clip and in the long run to overflow-inline: clip.
Yeah, on the latest browser versions this would solve a very old problem. Legacy browser support is what always holds back requests like this. When you're building a landing page and these kinds of edge cases come up, it doesn't really matter that you can easily fix them in modern browsers - if a visitor on an old browser gets put off by a simple text-rendering glitch. And to make it worse, it's not even something you caused, yet they still associate the poor experience with "bad" work or low quality.
Btw here a example utility with text-box (Chrome 133, Safari 18.2, Firefox doesn't support yet):
- https://play.tailwindcss.com/56A5JFMq0Z?size=540x720&file=css