Tag text-overflow

🔠 CSS text-overflow — Controlling Overflowing Text with Style

The text-overflow property lets you control how text is displayed when it overflows its container — particularly in single-line or restricted-width elements. It works beautifully with ellipsis (…), clipping, and even custom behaviors.


🔹 What Does text-overflow Do?

It determines what happens when text doesn’t fit inside its container and must be cut off. It’s especially useful in UI components like buttons, cards, nav bars, or tables.


📘 Syntax

selector {
text-overflow: clip | ellipsis | string;
}

✅ Important: It only works if overflow is hidden and white-space is nowrap.


💡 Values Explained

ValueDescription
clipCuts off the overflow text without any indicator.
ellipsisAdds  at the end of the text when it overflows.
<string>You can provide a custom string (experimental; limited support).

✍️ Example: Truncating Text with Ellipsis

<div class="truncate">
This is a very long title that won’t fit in a small box.
</div>
.truncate {
width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

✅ Result: You’ll see something like:

This is a very long title that won’t…


🖼️ Image Idea: Side-by-Side Comparison

Image Description:

Column 1Column 2Column 3
Normal textClipped textEllipsis text
Full lineText is cut offText ends with 

🎯 Purpose: Show visually how clip and ellipsis behave differently.


🧠 Tips for Usage

  • Common with one-liner UIs, like:
    • Cards
    • Navigation menus
    • Table cells
    • File names or article titles
  • Combine with:
white-space: nowrap;
overflow: hidden;

To prevent wrapping and hide the overflow.


🧪 Bonus: Multiline Ellipsis (Advanced)

CSS text-overflow doesn’t work on multiline by default, but you can mimic the effect using line-clamp:

.multiline-ellipsis {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}

✅ This will truncate text after 2 lines and add ellipsis (in supported browsers).


✅ Best Use Cases

ScenarioApply text-overflow?
Truncating file names✅ Yes, with ellipsis
Shortening news headlines✅ Yes
Keeping table columns neat✅ Yes
Full text readability❌ No — use wrap or tooltip

✅ Summary

Propertytext-overflow
ControlsHow overflowed inline text is handled
Valuesclipellipsis, (limited) custom string
Requiresoverflow: hidden and white-space: nowrap
Works onBlock or inline-block elements
Great forCards, buttons, labels, table cells

🔚 Final Thought

text-overflow is one of those elegant CSS tools that improve readability and UX without JavaScript. When space is tight, this is your best friend for creating clean, professional interfaces.