Definition and Usage
The text-overflow CSS property determines how overflowed content that is not displayed is signaled to the users. It can be clipped, or display an ellipsis ('…', U+2026 Horizontal Ellipsis) or a Web author-defined string.
Clipping happens at the border of the box; to clip at the character limit an empty custom string can be used ('').
This property only affects content that is overflowing a block container element in its inline progression direction (not text overflowing at the bottom of a box, for example). Text can overflow when it is prevented from wrapping (e.g., due to ‘white-space:nowrap’) or a single word being too long to fit.
This CSS property doesn't force an overflow to occur; to do so and make text-overflow to be applied, the author must apply some additional properties on the element, like setting overflow to hidden.
- Initial clip
- Applies to block container elements
- Inherited no
- Media visual
- Computed Value as specified
- Animatable no
- Canonical order the unique non-ambiguous order defined by the formal grammar
Syntax
Formal syntax: [ clip | ellipsis | <string> ]{1,2}
/* One-value syntax: the value describes the overflow performed at the end of the line (right end if ltr, left end if rtl) */ text-overflow: clip text-overflow: ellipsis text-overflow: "…" /* Two-value syntax: the first value describes the overflow at the left end of the line, the second at the right end. Directionality has no influence */ text-overflow: clip ellipsis text-overflow: "…" "…" text-overflow: inherit
Values
- clip
- This keyword value indicates to truncate the text at the limit of the content area, therefore the truncation can happen in the middle of a character. To truncate at the transition between two characters, the empty string value ('') must be used. The value clip is the default for this property.
- ellipsis
- This keyword value indicates to display an ellipsis ('…', U+2026 Horizontal Ellipsis) to represent clipped text. The ellipsis is displayed inside the content area, decreasing the amount of text displayed. If there is not enough space to display the ellipsis, it is clipped.
- <string>
- The <string> to be used to represent clipped text. The string is displayed inside the content area, shortening more the size of the displayed text. If there is not enough place to display the string itself, it is clipped.
Examples
p { white-space: nowrap; width: 100%; overflow: hidden; /* "overflow" value must be different from "visible" */ text-overflow: ellipsis; }
CSS value | direction: ltr | direction: rtl | ||
---|---|---|---|---|
Expected Result | Live result | Expected Result | Live result | |
visible overflow | 1234567890 | 1234567890 | 0987654321 | 1234567890 |
text-overflow: clip | ||||
text-overflow: '' | 12345 | 54321 | ||
text-overflow: ellipsis | 1234… | …4321 | ||
text-overflow: '.' | 1234. | .4321 | ||
text-overflow: clip clip | 123456 | 654321 | ||
text-overflow: clip ellipsis | 1234… | 6543… | ||
text-overflow: clip '.' | 1234. | 6543. | ||
text-overflow: ellipsis clip | …3456 | …4321 | ||
text-overflow: ellipsis ellipsis | …34… | …43… | ||
text-overflow: ellipsis '.' | …34. | …43. | ||
text-overflow: ',' clip | ,3456 | ,4321 | ||
text-overflow: ',' ellipsis | ,34… | ,43… | ||
text-overflow: ',' '.' | ,34. | ,53. |
Compatibility
Desktop browsers
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 (312.3) | 7.0 | 6.0 | 9-o 11.0 | 1.3 (312.3) |
Two-value syntax | Not supported | 9.0 (9.0) | Not supported | Not supported | Not supported |
String value | Not supported | 9.0 (9.0) | Not supported | Not supported | Not supported |
Mobile browsers
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | (Yes) | 7.0 (7.0) | NA | (Yes) | (Yes) |
Two-value syntax | Not supported | 9.0 (9.0) | Not supported | Not supported | Not supported |
String value | Not supported | 9.0 (9.0) | Not supported | Not supported | Not supported |