mozilla

Revision 25075 of text-overflow

  • Revision slug: CSS/text-overflow
  • Revision title: text-overflow
  • Revision id: 25075
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment WIP (saved for archive); 92 words added

Revision Content

Summary

The text-overflow CSS property determines how overflowed content that is not displayed is signaled to the users. It can be clipped, display an ellipsis ('', U+2026 Horizontal Ellipsis) or a Web author-defined string.

text-overflow.png

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 {{ cssxref("overflow") }} to hidden.

  • {{ xref_cssinitial() }}: clip
  • Applies to: all block elements
  • {{ xref_cssinherited() }}: no
  • Media: {{ xref_cssvisual() }}
  • {{ xref_csscomputed() }}: the specified one.

Syntax

text-overflow: inherit                                 or
text-overflow: end-overflow-type                       or
text-overflow: left-overflow-type right-overflow-type

where :

inherit
Is a keyword indicating to use the value of this CSS property that the parent element of the element uses.
end-overflow-type
Is an <overflow-type> CSS value describing the overflow to perform at the end of the line. The end of the line is its right end if the text is written with left-to-right directionality, it is its left end if the text is written with right-to-left directionality.
left-overflow-type
Is an <overflow-type> CSS value describing the overflow to perform at the left end of the line. The directionality of the text has no influence on which end of the line is affected.
right-overflow-type
Is an <overflow-type> CSS value describing the overflow to perform at the right end of the line. The directionality of the text has no influence on which end of the line is affected.

<overflow-type>

The <overflow-type> CSS type describes how text overflow, when not visible, must be handled. The following values are valid:

clip
This keyword value indicates to truncate the text at the limit of the content area. This is the default value.
ellipsis
This keyword value indicates to display ellipses ('', U+2026 Horizontal Ellipsis) to represent clipped text. The ellipsis is displayed inside the content area, shortening more the size of the displayed text. If there is not enough place to display ellipsis, they are clipped.
string
The {{ xref_cssstring() }} 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 string, they are clipped.

Example

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
no overflow 1234567890 1234567890 0987654321 1234567890
text-overflow: clip 123456 1234567890 654321 1234567890
text-overflow: ellipsis 1234… 1234567890 …4321 1234567890
text-overflow: '.' 12345. 1234567890 .54321 1234567890
text-overflow: clip clip   1234567890   1234567890
text-overflow: clip ellipsis   1234567890   1234567890
text-overflow: clip '.'   1234567890   1234567890
text-overflow: ellipsis clip   1234567890   1234567890
text-overflow: ellipsis ellipsis   1234567890   1234567890
         
         
         
         

Specifications

Specification Status Comment
CSS Basic User Interface Level 3 {{ Spec2('CSS3 UI') }}  

A previous version of this interface reached the Candidate Recommendation status. As some not-listed-at-risk features needed to be removed, the spec was demoted to the Working Draft level, explaining why browsers implemented this property unprefixed, though not at the CR state.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 (312.3) {{ CompatGeckoDesktop("7.0") }} 6.0 [*] 11 [**] 1.3 (312.3)
Two-value syntax {{ CompatNo() }} {{ CompatGeckoDesktop("9.0") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
String value {{ CompatNo() }} {{ CompatGeckoDesktop("9.0") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatGeckoMobile("7.0") }} {{ CompatUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Two-value syntax {{ CompatNo() }} {{ CompatGeckoMobile("9.0") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
String value {{ CompatNo() }} {{ CompatGeckoMobile("9.0") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

[*] IE8 introduced the prefixed version, -ms-text-overflow, synonymous with text-overflow.

[**] Opera supported the prefixed version, -o-text-overflow, from version 9.0 on.

See also

  • CSS Reference index
  • Related CSS properties: {{ cssxref("overflow") }}, {{ cssxref("white-space") }}

{{ HTML5ArticleTOC() }}

{{ languages({"ja": "ja/CSS/Text-overflow"}) }}

Revision Source

<h2>Summary</h2>
<p>The <code>text-overflow</code> <a href="/en/CSS" title="CSS">CSS</a> property determines how overflowed content that is not displayed is signaled to the users. It can be clipped, display an ellipsis ('<code>…</code>', <code style="text-transform:uppercase">U+2026 Horizontal Ellipsis</code>) or a Web author-defined string.</p>
<p><img alt="text-overflow.png" class="internal default" src="/@api/deki/files/5846/=text-overflow.png" style=""></p>
<p>This CSS property doesn't force an overflow to occur, to do so and make <code>text-overflow </code>to be applied, the author must apply some additional properties on the element, like setting {{ cssxref("overflow") }} to <code>hidden</code>.</p>
<ul> <li>{{ xref_cssinitial() }}: <code>clip</code></li> <li>Applies to: all block elements</li> <li>{{ xref_cssinherited() }}: no</li> <li>Media: {{ xref_cssvisual() }}</li> <li>{{ xref_csscomputed() }}: the specified one.</li>
</ul><h2>Syntax</h2>
<pre class="eval">text-overflow: inherit                                 or
text-overflow: <em>end-overflow-type              </em><code>         <em>or</em></code>
<em><code>text-overflow: </code></em><code><em>left-overflow-type<code> </code>right-overflow-type</em></code>
</pre>
<p>where :</p>
<dl> <dt style="margin-left: 40px;"><code>inherit</code></dt> <dd style="margin-left: 80px;">Is a keyword indicating to use the value of this CSS property that the parent element of the element uses.</dd> <dt style="margin-left: 40px;"><em>end-overflow-type</em></dt> <dd style="margin-left: 80px;">Is an <a href="/#.3Coverflow-type.3E" title="#.3Coverflow-type.3E"><code>&lt;overflow-type&gt;</code></a> CSS value describing the overflow to perform at the end of the line. The end of the line is its <em>right</em> end if the text is written with <em>left-to-right</em> directionality, it is its <em>left</em> end if the text is written with <em>right-to-left</em> directionality.</dd> <dt style="margin-left: 40px;"><em>left-overflow-type</em></dt> <dd style="margin-left: 80px;">Is an <a href="/#.3Coverflow-type.3E" title="#.3Coverflow-type.3E"><code>&lt;overflow-type&gt;</code></a> CSS value describing the overflow to perform at the <em>left</em> end of the line. The directionality of the text has no influence on which end of the line is affected.</dd> <dt style="margin-left: 40px;"><em>right-overflow-type</em></dt> <dd style="margin-left: 80px;">Is an <a href="/#.3Coverflow-type.3E" title="#.3Coverflow-type.3E"><code>&lt;overflow-type&gt;</code></a> CSS value describing the overflow to perform at the <em>right</em> end of the line. The directionality of the text has no influence on which end of the line is affected.</dd>
</dl>
<h3><code>&lt;overflow-type&gt;</code></h3>
<p>The &lt;overflow-type&gt; CSS type describes how text overflow, when not visible, must be handled. The following values are valid:</p>
<dl> <dt><code>clip</code></dt> <dd>This keyword value indicates to truncate the text at the limit of the content area. This is the default value.</dd> <dt><code>ellipsis</code></dt> <dd>This keyword value indicates to display ellipses ('<code>…</code>', <code style="text-transform:uppercase">U+2026 Horizontal Ellipsis</code>) to represent clipped text. The ellipsis is displayed inside the content area, shortening more the size of the displayed text. If there is not enough place to display ellipsis, they are clipped.</dd> <dt><em>string</em></dt> <dd>The {{ xref_cssstring() }} 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 string, they are clipped.</dd>
</dl><h2>Example</h2>
<pre class="brush: css">p {
  white-space: nowrap;
  width: 100%;                   
  overflow: hidden;              /* "overflow" value must be different from "visible" */ 

  text-overflow:    ellipsis;
}
</pre>
<table border="1" cellpadding="1" cellspacing="1" style="width: 100%;"> <thead> <tr> <th colspan="1" rowspan="2" scope="col">CSS value</th> <th colspan="2" rowspan="1" scope="col"><strong><code>direction: ltr</code></strong></th> <th colspan="2" rowspan="1" scope="col"><code>direction: rtl</code></th> </tr> <tr> <th scope="col">Expected Result</th> <th scope="col">Live result</th> <th scope="col">Expected Result</th> <th scope="col">Live result</th> </tr> </thead> <tbody> <tr> <td><em>no overflow</em></td> <td>1234567890</td> <td>1234567890</td> <td>0987654321</td> <td>1234567890</td> </tr> <tr> <td><code>text-overflow: clip</code></td> <td>123456</td> <td>1234567890</td> <td>654321</td> <td>1234567890</td> </tr> <tr> <td><code>text-overflow: ellipsis</code></td> <td>1234…</td> <td>1234567890</td> <td>…4321</td> <td>1234567890</td> </tr> <tr> <td><code>text-overflow: '.'</code></td> <td>12345.</td> <td>1234567890</td> <td>.54321</td> <td>1234567890</td> </tr> <tr> <td><code>text-overflow: clip clip</code></td> <td> </td> <td>1234567890</td> <td> </td> <td>1234567890</td> </tr> <tr> <td><code>text-overflow: clip ellipsis</code></td> <td> </td> <td>1234567890</td> <td> </td> <td>1234567890</td> </tr> <tr> <td><code>text-overflow: clip '.'</code></td> <td> </td> <td>1234567890</td> <td> </td> <td>1234567890</td> </tr> <tr> <td><code>text-overflow: ellipsis clip</code></td> <td> </td> <td>1234567890</td> <td> </td> <td>1234567890</td> </tr> <tr> <td><code>text-overflow: ellipsis ellipsis</code></td> <td> </td> <td>1234567890</td> <td> </td> <td>1234567890</td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </tbody>
</table>
<h2>Specifications</h2>
<table class="standard-table"> <thead> <tr style="background-color: rgb(255, 204, 255);"> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td><a class="external" href="http://dev.w3.org/csswg/css3-ui/#text-overflow" title="http://dev.w3.org/csswg/css3-ui/#text-overflow">CSS Basic User Interface Level 3</a></td> <td>{{ Spec2('CSS3 UI') }}</td> <td> </td> </tr> </tbody>
</table>
<p>A previous version of this interface reached the <em>Candidate Recommendation</em> status. As some not-listed-at-risk features needed to be removed, the spec was demoted to the <em>Working Draft</em> level, explaining why browsers implemented this property unprefixed, though not at the CR state.</p><h2>Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>1.0 (312.3)</td> <td>{{ CompatGeckoDesktop("7.0") }}</td> <td>6.0 [*]</td> <td>11 [**]</td> <td>1.3 (312.3)</td> </tr> <tr> <td>Two-value syntax</td> <td>{{ CompatNo() }}</td> <td>{{ CompatGeckoDesktop("9.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> <tr> <td>String value</td> <td>{{ CompatNo() }}</td> <td>{{ CompatGeckoDesktop("9.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoMobile("7.0") }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> <tr> <td>Two-value syntax</td> <td>{{ CompatNo() }}</td> <td>{{ CompatGeckoMobile("9.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> <tr> <td>String value</td> <td>{{ CompatNo() }}</td> <td>{{ CompatGeckoMobile("9.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<p>[*] IE8 introduced<code> </code>the prefixed version, <code>-ms-text-overflow</code>, synonymous with <code>text-overflow</code>.</p>
<p>[**] Opera supported the prefixed version, <code>-o-text-overflow</code>, from version 9.0 on.</p><h2>See also</h2>
<ul> <li><a href="/en/CSS/CSS_Reference" title="CSS Reference">CSS Reference</a> index</li> <li>Related CSS properties: {{ cssxref("overflow") }}, {{ cssxref("white-space") }}</li>
</ul>
<p>{{ HTML5ArticleTOC() }}</p>
<p>{{ languages({"ja": "ja/CSS/Text-overflow"}) }}</p>
Revert to this revision