Text-overflow: ellipsis considered harmful

Eric Eggert:

There are a few legitimate use cases for this technique. For example, you might have a table with titles and descriptions. To preserve more space for the title, you constrain the description to one line on small


Text-overflow: ellipsis considered harmful originally published on CSS-Tricks. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Geoff Graham

Eric Eggert:

There are a few legitimate use cases for this technique. For example, you might have a table with titles and descriptions. To preserve more space for the title, you constrain the description to one line on small viewports to the one-line and you repeat the description on the detail page for this item.

However, I often see it used on items like buttons or even form labels to make them look nicer(?) or when aligning them vertically. But once you change the viewport or resize the text, the end of the text disappears.

I think “… if used in certain situations” belongs there, but it certainly makes for a better blog post title without it. As Eric says, there are legitimate use cases for truncating text. Maybe only a few, but legitimate nonetheless.

The ultimate goal is to prevent “losing” data, something that can certainly happen in CSS. Text that inadvertently overflows a container is lost in the sense that it’s simply not there. And if that text is simply not there, users will miss it, even if it is the best and most well-crafted call to action ever published to the web.

Eric points out that there is no way to make the text truncated by text-overflow: ellipsis visible. Once it’s gone, it’s gone (although screen readers seem to announce it). It’s practically lost data. You might be OK with that. That’s cool as long as you know what’s happening and it’s intended.

But here’s what Eric says that made me want to share this:

Don’t constrain the content to fit your design, make your CSS flexible to handle longer words gracefully.

Again, you might want to conform content to the design. But I’d probably argue, like Eric, that the design should adapt to the content rather than the other way around. I have a hard time recalling any situation where the text on a page is unimportant or without purpose to the extent that I’d be cool cutting if off at any arbitrary point determined by a CSS property. Maybe an archive of blog posts where each post shows an excerpt of the post content before truncating, but that’s not exactly a use case for text-overflow: ellipse.

CSS has the tools to make a flexible design that accounts for varying lengths of text. So maybe err on the side of writing defensive CSS… CSS that anticipates issues and knows how to gracefully handle different content scenarios. text-overflow: ellipsis might be part of your CSS arsenal for that. But it might also be throwing the baby out with the bath water. Worth asking whether losing that data is worth the cost of what that content is supposed to do before giving giving it a haircut.

While we’re talking about truncating text…

To Shared LinkPermalink on CSS-Tricks


Text-overflow: ellipsis considered harmful originally published on CSS-Tricks. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Geoff Graham


Print Share Comment Cite Upload Translate Updates
APA

Geoff Graham | Sciencx (2022-06-30T13:38:16+00:00) Text-overflow: ellipsis considered harmful. Retrieved from https://www.scien.cx/2022/06/30/text-overflow-ellipsis-considered-harmful/

MLA
" » Text-overflow: ellipsis considered harmful." Geoff Graham | Sciencx - Thursday June 30, 2022, https://www.scien.cx/2022/06/30/text-overflow-ellipsis-considered-harmful/
HARVARD
Geoff Graham | Sciencx Thursday June 30, 2022 » Text-overflow: ellipsis considered harmful., viewed ,<https://www.scien.cx/2022/06/30/text-overflow-ellipsis-considered-harmful/>
VANCOUVER
Geoff Graham | Sciencx - » Text-overflow: ellipsis considered harmful. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/30/text-overflow-ellipsis-considered-harmful/
CHICAGO
" » Text-overflow: ellipsis considered harmful." Geoff Graham | Sciencx - Accessed . https://www.scien.cx/2022/06/30/text-overflow-ellipsis-considered-harmful/
IEEE
" » Text-overflow: ellipsis considered harmful." Geoff Graham | Sciencx [Online]. Available: https://www.scien.cx/2022/06/30/text-overflow-ellipsis-considered-harmful/. [Accessed: ]
rf:citation
» Text-overflow: ellipsis considered harmful | Geoff Graham | Sciencx | https://www.scien.cx/2022/06/30/text-overflow-ellipsis-considered-harmful/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.