<pre class="metadata">
Title: CSS Overflow Module Level 3
Status: ED
Work Status: Revising
ED: https://drafts.csswg.org/css-overflow-3/
Shortname: css-overflow
Group: csswg
Level: 3
TR: https://www.w3.org/TR/css-overflow-3/
Previous version: https://www.w3.org/TR/2018/WD-css-overflow-3-20180731/
Previous version: https://www.w3.org/TR/2016/WD-css-overflow-3-20160531/
Previous version: https://www.w3.org/TR/2013/WD-css-overflow-3-20130418/
Editor: L. David Baron, Mozilla https://www.mozilla.org/, https://dbaron.org/, w3cid 15393
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Florian Rivoal, On behalf of Bloomberg, http://florian.rivoal.net/, w3cid 43241
Abstract: This module contains the features of CSS relating to scrollable overflow handling in visual media.
!Change Log: <a href="https://hg.csswg.org/drafts/log/tip/css-overflow/Overview.bs">from 27 January 2015 to the present</a>
!Change Log: <a href="https://hg.csswg.org/drafts/log/tip/css-overflow/Overview.src.html">from 28 March 2013 to 27 January 2015</a>
!Change Log: <a href="https://hg.csswg.org/drafts/log/tip/css3-overflow/Overview.src.html">from 31 July 2012 to 27 March 2013</a>
Ignored Vars: B, P
Ignored Terms: padding edge, viewport, line box, flex order, -webkit-box-orient
At Risk: the 'max-lines' property
Status Text: <strong>This update trims away most of the experimental new ideas
   for handling overflow that were described in the <a href="https://www.w3.org/TR/2013/WD-css-overflow-3-20130418/">previous Working Draft</a>.
   These ideas are not abandoned; they are merely <a href="https://drafts.csswg.org/css-overflow/">deferred until Level 4</a>.</strong>
   Level 3 is focused solely on completing a spec for the existing, shipped 'overflow' features;
   work will resume on fragmented overflow and other fun things once this is completed.
</pre>
<!-- FIXME: Regressions from bikeshed conversion: -->
<!-- - Value lines in propdef tables no longer link to #values. -->
<!-- - no longer says "Test suite: none yet" -->
<!-- - Abstract has the most introductory sentence last -->
<!-- FIXME: other bikeshed issues -->
<pre class="link-defaults">
spec:css-transforms-2; type:property; text:transform-style
type: dfn; spec:css-multicol-1; text:overflow column
type: dfn; spec:css-transforms-2; text:3d rendering context
spec:css-writing-modes-4; type:dfn; text:end
spec:css-pseudo-4; type:selector; text:::first-line
spec:css-pseudo-4; type:selector; text:::first-letter
spec:css-display-3; type:property; text:display
</pre>
<!-- FIXME: the break-* link doesn't actually work! -->
<pre class="anchors">
url: https://www.w3.org/TR/2008/CR-css3-marquee-20081205/#the-overflow-style; type: property; text: overflow-style;
url: https://www.w3.org/TR/CSS22/visuren.html#positioned-element; type: dfn; spec:css2; text:positioned;
url: https://www.w3.org/TR/CSS22/visudet.html#strut-element; type: dfn; spec:css2; text:strut;
</pre>
<style>
.awesome-table td { padding: 5px; }
.awesome-table {
	color: #000;
	background: #fff;
	margin: auto;
}
</style>

<h2 id="intro">
Introduction</h2>

	In CSS Level 1 [[CSS1]], placing more content than would fit
	inside an element with a specified size
	was generally an authoring error.
	Doing so caused the content to extend
	outside the bounds of the element,
	which would likely cause
	that content to overlap with other elements.

	CSS Level 2 [[CSS21]] introduced the 'overflow' property,
	which allows authors to have overflow be handled by scrolling,
	which means it is no longer an authoring error.
	It also allows authors to specify
	that overflow is handled by clipping,
	which makes sense when the author's intent
	is that the content not be shown.

	This specification introduces the long-standing de-facto 'overflow-x' and 'overflow-y' properties,
	adds a ''overflow/clip'' value,
	and defines overflow handling more fully.

	[Something something 'max-lines'.]

	Note: This specification also reproduces the definition of the 'text-overflow' property
	previously defined in [[CSS-UI-3]],
	with no addition or modification,
	in order to present 'text-overflow' and 'block-ellipsis' toghether.

<!--
████████ ██    ██ ████████  ████████  ██████
   ██     ██  ██  ██     ██ ██       ██    ██
   ██      ████   ██     ██ ██       ██
   ██       ██    ████████  ██████    ██████
   ██       ██    ██        ██             ██
   ██       ██    ██        ██       ██    ██
   ██       ██    ██        ████████  ██████
-->

<h2 id="overflow-concepts">
Types of Overflow</h2>

	CSS uses the term <dfn export>overflow</dfn> to describe
	the contents of a box
	that extend outside one of that box's edges
	(i.e., its <i>content edge</i>, <i>padding edge</i>,
	<i>border edge</i>, or <i>margin edge</i>).
	The term might be interpreted as
	elements or features that cause this overflow,
	the non-rectangular region occupied by these features,
	or, more commonly, as
	the minimal rectangle that bounds that region.
	A box's overflow is computed based on the layout and styling of the box itself
	and of all descendants whose <a>containing block chain</a>
	includes the box.

	In most cases, <a>overflow</a>
	can be computed for any box
	from the bounds and properties of that box itself,
	plus the <a>overflow</a>
	of each of its children.
	However, this is not always the case; for example,
	when ''transform-style: preserve-3d'' [[CSS3-TRANSFORMS]] is used on
	some of the children, any of their descendants with
	''transform-style: preserve-3d'' must also be examined.

	There are two different types of overflow,
	which are used for different purposes by the UA:

	<ul>
		<li><a>ink overflow</a>
		<li><a>scrollable overflow</a>
	</ul>

<h3 id="ink">Ink Overflow</h3>

	The <dfn export>ink overflow</dfn> of a box
	is the part of that box and its contents that
	creates a visual effect outside of
	the box's border box.
	Ink overflow is the overflow of painting effects defined to not affect layout
	or otherwise extend the <a>scrollable overflow region</a>,
	such as <a href="https://www.w3.org/TR/css-backgrounds/#box-shadow">box shadows</a>,
	<a href="">border images</a>,
	<a href="https://www.w3.org/TR/css-text-decor-3/">text decoration</a>,
	overhanging glyphs (with negative side bearings,
	or with ascenders/descenders extending outside the em box),
	<a href="https://www.w3.org/TR/CSS2/ui.html#dynamic-outlines">outlines</a>,
	etc.

	Since some effects in CSS (for example, the blurs in
	'text-shadow' [[CSS-TEXT-3]] and 'box-shadow' [[CSS-BACKGROUNDS-3]],
	which are theoretically infinite)
	do not define what visual extent they cover, the extent
	of the <a>ink overflow</a> is undefined.

	The <dfn export>ink overflow region</dfn> is the non-rectangular area
	occupied by the <a>ink overflow</a>
	of a box and its contents,
	and the <dfn export>ink overflow rectangle</dfn> is
	the minimal rectangle whose axes are aligned to the box's axes
	and that contains the <a>ink overflow region</a>.
	Note that the <a>ink overflow rectangle</a> is a rectangle
	in the box's coordinate system, but might be non-rectangular
	in other coordinate systems due to transforms. [[CSS3-TRANSFORMS]]


<h3 id="scrollable">
Scrollable Overflow</h3>

	The <dfn export>scrollable overflow</dfn> of a box is the
	set of things extending outside of that box's padding edge
	for which a scrolling mechanism needs to be provided.

	The <dfn export>scrollable overflow region</dfn> is the non-rectangular region
	occupied by the <a>scrollable overflow</a>, and the
	<dfn export>scrollable overflow rectangle</dfn> is
	the minimal rectangle whose axes are aligned to the box's axes
	and that contains the <a>scrollable overflow region</a>.

	The <a>scrollable overflow region</a> is the union of:
	<ul>
		<li>
			the box’s own content and padding areas

			<div class=issue>
				There's disagreement on the scrolling model.
				2.1 apparently defined that you scrolled the *content* area;
				the content would overflow the content-box,
				and you would union that overflow with the content box to find the scrollable area.
				In particular, this means that the content would be offset by the start-sides padding,
				but if it overflowed,
				it would go right to the edge on the end sides.
				This is what Firefox and IE do.

				At least some authors (and spec authors)
				instead have the mental model that the padding box is what's scrollable,
				so when you scroll to the end of the overflow,
				there's the right/bottom padding.
				Chrome/WebKit do this for the block axis, at least.
				They're somewhat inconsistent for the inline axis;
				there's something weird about how they handle lineboxes.

				It seems that the block-axis padding is probably web-compatible to honor.
				It's unclear that the inline-axis padding will be.
				Further experimentation is needed.
			</div>


		<li>
			all line boxes directly contained by the box

		<li>
			the border boxes
			of all boxes for which it is the containing block
			and whose border boxes are positioned not wholly outside
			its <a>block-start</a> or <a>inline-start</a> padding edges,
			accounting for transforms by projecting each box onto
			the plane of the element that establishes its <a>3D rendering context</a>.
			[[!CSS3-TRANSFORMS]]

			Issue: Is this description of handling transforms
			sufficiently accurate?

		<li>
			the <a>scrollable overflow regions</a> of all of the above boxes
			(accounting for transforms as described above),
			provided they themselves have ''overflow: visible''
			(i.e. do not themselves trap the overflow)
			and that <a>scrollable overflow</a> is not already clipped
			(e.g. by the 'clip' property or the 'contain' property).

			Issue: should ''overflow: clip'' also clip the <a>scrollable overflow</a>
			or should it remain a pure paint-time operation,
			which would mean that scrollable overflow, while invisible, would still be scrollable.

			Note: The 'mask-*' properties [[!CSS-MASKING-1]]
			do not affect the <a>scrollable overflow region</a>.

			Issue: Need to evaluate compat of honoring or ignoring 'clip' and 'clip-path'.

		<li>
			Padding on the end-edge sides of the <a>scrollable overflow rectangle</a>
			representing the end-side padding applied to the <a>scroll container</a>,
			added such that its content can be scrolled to a position
			that would satisfy the requirements of ''place-content: end'' alignment.
			Including this padding is optional for <a>block containers</a>
			in any axis whose corresponding <a>content-distribution property</a>
			('align-content'/'justify-content')
			is ''align-content/normal''.

			Issue(129): It's not yet clear if including the end-side padding in the scrollable layer of block containers is Web-compatible, so this clause is under investigation.
			It appears that Chrome and Safari include such padding <a href="https://bug748518.bmoattachments.org/attachment.cgi?id=618078">in the block axis</a>;
			and the behavior in the inline axis is <a href="http://jsbin.com/digadoyohi/1/edit?html,css,output">not</a> <a href="http://jsbin.com/vexahocayi/1/edit?html,css,output">clear</a>.

			<!-- Make sure http://jsbin.com/qececaqilo/edit?html,css,output is clearly defined. -->

		<li>
			the margin areas of <a>grid item</a> and <a>flex item</a> boxes
			for which the box establishes a containing block.
			The UA may <em>additionally</em> include
			the margin areas of other boxes
			for which the box establishes a containing block;
			however,
			the conditions under which such margin areas are included
			is undefined in this level.
			<span class="issue">This needs further testing and investigation;
			is therefore deferred in this draft.</span>
	</ul>

	<!--
	Considerations:
	  * floats
	  * relpos
	  * margins that collapsed through to the edge of the scrollable area
	  * inline-side margins on both blocks and inlines
	Notes:
	  The reasoning for only including border boxes is to minimize the cases
	  in which overflow scrolling is triggered; however once overflow is triggered,
	  excluding margins creates tight, uncomfortable edges
	  because the margin has been effectively truncated.
	Testcase:
		http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Cstyle%3E%0A%20%20div%20%7B%20height%3A%2050px%3B%20overflow%3A%20scroll%3B%20border%3A%20solid%3B%20position%3A%20relative%3B%7D%0A%20%20p%20%7B%20margin%3A%2025px%3B%20background%3A%20red%3B%20%7D%0A%20%20q%20%7B%20position%3A%20absolute%3B%20background%3A%20blue%3B%20top%3A%2025px%3B%20margin%3A%2025px%3B%20%7D%0A%3C%2Fstyle%3E%0A%3Cdiv%3E%0A%20%20%3Cp%3ETest%20%3Cq%3ETest2%0A%3C%2Fdiv%3E
	-->

	Note: The <a>scrollable overflow rectangle</a> is always a rectangle
	in the box's own coordinate system, but might be non-rectangular
	in other coordinate systems due to transforms [[CSS3-TRANSFORMS]].
	This means scrollbars can sometimes appear when not actually necessary.

<!--
 ███████  ██     ██ ████████ ████████  ████████ ██        ███████  ██      ██
██     ██ ██     ██ ██       ██     ██ ██       ██       ██     ██ ██  ██  ██          ██   ██
██     ██ ██     ██ ██       ██     ██ ██       ██       ██     ██ ██  ██  ██           ██ ██
██     ██ ██     ██ ██████   ████████  ██████   ██       ██     ██ ██  ██  ██ ███████ █████████
██     ██  ██   ██  ██       ██   ██   ██       ██       ██     ██ ██  ██  ██           ██ ██
██     ██   ██ ██   ██       ██    ██  ██       ██       ██     ██ ██  ██  ██          ██   ██
 ███████     ███    ████████ ██     ██ ██       ████████  ███████   ███  ███
-->

<h2 id="overflow-properties">
Scrolling and Clipping Overflow: the 'overflow-x', 'overflow-y', and 'overflow' properties</h2>

	These properties specify whether a box’s content
	(including any <a>ink overflow</a>)
	is clipped to its padding edge,
	and if so,
	whether it is a <dfn export>scroll container</dfn>
	that allows the user to scroll clipped parts of its <a>scrollable overflow region</a>
	into view.
	The visual viewport of the <a>scroll container</a>
	(through which the <a>scrollable overflow region</a> can be viewed)
	coincides with its padding box,
	and is called the <dfn export>scrollport</dfn>.

	<pre class=propdef>
		Name: overflow-x, overflow-y
		Value: visible | hidden | clip | scroll | auto
		Initial: ''visible''
		Applies to: block containers [[!CSS21]], flex containers [[!CSS3-FLEXBOX]], and grid containers [[!CSS3-GRID-LAYOUT]]
		Inherited: no
		Percentages: N/A
		Computed value: as specified, except with ''visible''/''clip'' computing to ''overflow/auto''/''hidden'' (respectively) if one of 'overflow-x' or 'overflow-y' is neither ''visible'' nor ''clip''
		Animation type: discrete
	</pre>

	The 'overflow-x' property specifies
	the handling of <a>overflow</a> in the horizontal direction
	(i.e., overflow from the left and right sides of the box),
	and the 'overflow-y' property specifies the handling
	of <a>overflow</a> in the vertical direction
	(i.e., overflow from the top and bottom sides of the box).

	<pre class="propdef shorthand">
		Name: overflow
		Value: [ visible | hidden | clip | scroll | auto ]{1,2}
		Initial: visible
		Applies to: block containers [[!CSS21]], flex containers [[!CSS3-FLEXBOX]], and grid containers [[!CSS3-GRID-LAYOUT]]
		Inherited: no
		Percentages: N/A
		Computed value: see individual properties
		Animation type: discrete
	</pre>

	The 'overflow' property is a shorthand property
	that sets the specified values of 'overflow-x' and 'overflow-y' in that order.
	If the second value is omitted, it is copied from the first.

	Values have the following meanings:

	<dl dfn-for="overflow, overflow-x, overflow-y" dfn-type="value">
		<dt><dfn>visible</dfn>
		<dd>
			There is no special handling of overflow, that is,
			the box’s content is rendered outside the box if positioned there.
			The box is not a <a>scroll container</a>.

		<dt><dfn>hidden</dfn>
		<dd>
			This value indicates that
			the box’s content is clipped to its padding box
			and that the UA must not provide any scrolling user interface
			to view the content outside the clipping region,
			nor allow scrolling by direct intervention of the user,
			such as dragging on a touch screen
			or using the scrolling wheel on a mouse.
			However, the content must still be scrollable programatically,
			for example using the mechanisms defined in [[CSSOM-VIEW]],
			and the box is therefore still a <a>scroll container</a>.

		<dt><dfn>clip</dfn>
		<dd>
			Like ''hidden'',
			this value indicates that
			the box’s content is clipped to its padding box
			and that no scrolling user interface should be provided by the UA
			to view the content outside the clipping region.
			In addition, unlike ''overflow: hidden''
			which still allows programmatic scrolling,
			''overflow: clip'' forbids scrolling entirely,
			through any mechanism,
			and therefore the box is not a <a>scroll container</a>.

			Unlike ''hidden'', this value <strong>does not</strong> cause
			the element to establish a new formatting context.

			Note: Authors who also want the box to establish a formatting context
			may use ''display: flow-root'' together with ''overflow: clip''.

		<dt><dfn>scroll</dfn>
		<dd>
			This value indicates that
			the content is clipped to the padding box,
			but can be scrolled into view
			(and therefore the box is a <a>scroll container</a>).
			Furthermore, if the user agent uses a scrolling mechanism
			that is visible on the screen (such as a scroll bar or a panner),
			that mechanism should be displayed
			whether or not any of its content is clipped.
			This avoids any problem with scrollbars appearing
			and disappearing in a dynamic environment.
			When the target medium is ''print'',
			overflowing content may be printed;
			it is not defined where it may be printed.

		<dt><dfn>auto</dfn>
		<dd>
			Like ''overflow/scroll'' when the box has <a>scrollable overflow</a>;
			like ''overflow/hidden'' otherwise.
			Thus, if the user agent uses a scrolling mechanism
			that is visible on the screen (such as a scroll bar or a panner),
			that mechanism will only be displayed
			if there is overflow.
		</dl>

	If the computed value of 'overflow' on a <a>block box</a>
	is neither ''overflow/visible'' nor ''overflow/clip'' nor a combination thereof,
	it [=establishes an independent formatting context=] for its contents.


<h3 id="static-media">
Overflow in Print and Other Static Media</h3>

	<p class="advisement">
		Since scrolling is not possible in static media
		(such as print)
		authors should be careful to make content accessible in such media,
		for example by using ''@media print, (update: none) { &hellip; }''
		to adjust layout such that all relevant content
		is simultaneously visible.

	On <a>scroll containers</a> in non-interactive media
	with an 'overflow' value of ''overflow/auto'' or ''overflow/scroll''
	(but not ''overflow/hidden'')
	UAs may display an indication of any scrollable overflow,
	such as by displaying scrollbars
	or an ellipsis.

	Note: Not all paged media is non-interactive
	for example, e-book readers page content,
	but are interactive.

<h3 id="scrollbar-layout">
Scrollbars and Layout</h3>

	In the case of a scrollbar being placed on an edge of the element's box,
	it should be inserted between the inner border edge
	and the outer padding edge.
	Any space taken up by the scrollbars should be
	taken out of (subtracted from the dimensions of)
	the containing block formed by the element with the scrollbars.

	Issue: import examples from [[CSS3-BOX]].

<h3 id="scrolling-direction">
Scrolling Origin, Direction, and Restriction</h3>

	The <dfn export>initial scroll position</dfn>,
	that is, the initial position of
	the box’s <a>scrollable overflow region</a>
	with respect to its border box,
	prior to any user or programmatic scrolling that changes it,
	is dependent on the box’s <a>writing mode</a>,
	and is by default the <a>block-start</a>/<a>inline-start</a> edge
	of the box’s <a>padding edge</a>.
	However, the 'align-content' and 'justify-content' properties [[!CSS-ALIGN-3]]
	can be used to change this,
	see [[css-align-3#overflow-scroll-position]].

	Due to Web-compatibility constraints
	(caused by authors exploiting legacy bugs to surreptitiously hide content from visual readers but not search engines and/or speech output),
	UAs must clip the <a>scrollable overflow region</a>
	of <a>scroll containers</a>
	on the <a>block-start</a> and </a>inline-start</a> sides of the box
	(thereby behaving as if they had no <a>scrollable overflow</a> on that side).

	The viewport uses the <a>principal writing mode</a> for these calculations.

<h3 id="overflow-propagation">
Overflow Viewport Propagation</h3>

	UAs must apply the 'overflow-*' values
	set on the root element to the <a>viewport</a>.
	However,
	when the root element is an [[!HTML]] <{html}> element
	(including <a href="https://html.spec.whatwg.org/multipage/introduction.html#html-vs-xhtml">XML syntax for HTML</a>)
	whose 'overflow' value is ''overflow/visible'' (in both axes),
	and that element has a <{body}> element as a child,
	user agents must instead apply the 'overflow-*' values
	of the first such child element to the viewport.
	The element from which the value is propagated must then have
	a used 'overflow' value of ''overflow/visible''.

	The overflow values are not propagated to the viewport if no boxes are
	generated for the element whose overflow values
	would be used for the viewport (for example, if the root element has
	display: none).

	If ''overflow/visible'' is applied to the viewport,
	it must be interpreted as ''overflow/auto''.
	If ''overflow/clip'' is applied to the viewport,
	it must be interpreted as ''overflow/hidden''.

<h3 id=logical>
Flow Relative Properties: the 'overflow-block' and 'overflow-inline' properties</h3>

The following properties are processed according to the same processing model
as the Flow-Relative box model properties defined in [[css-logical-1#box]].

  <pre class="propdef">
  Name: overflow-inline, overflow-block
  Value: <<'overflow'>>
  Initial: visible
  Applies to: Same as 'overflow-x' and 'overflow-y'
  Inherited: no
  Percentages: N/A
  Computed value: Same as 'overflow-x' and 'overflow-y'
  Animation type: discrete
  </pre>

  These properties correspond to the
  'overflow-x' and 'overflow-y' properties.
  The mapping depends on the element's 'writing-mode'.

<h2 id="auto-ellipsis">
Automatic Ellipses</h2>

<h3 id="text-overflow" caniuse="text-overflow">
    Overflow Ellipsis: the 'text-overflow' property</h3>

<pre class="propdef">
Name: text-overflow
Value: clip | ellipsis
Initial: clip
Applies to: block containers
Inherited: no
Percentages: N/A
Computed value: specified keyword
Animation type: discrete
</pre>

This property specifies rendering when inline content overflows
its <a>end</a> line box edge
in the inline progression direction of its block container element ("the block")
that has 'overflow'
other than ''visible''.

Text can overflow for example when it is prevented from wrapping
(e.g. due to <code class="lang-css">white-space: nowrap</code>
or a single word is too long to fit).
Values have the following meanings:

<dl data-dfn-for="text-overflow" class="valuedef">
  <dt><dfn id=overflow-clip dfn-type=value>clip</dfn></dt>
    <dd>Clip inline content that overflows its block container element. Characters may be only partially rendered.</dd>

  <dt><dfn id=overflow-ellipsis dfn-type=value>ellipsis</dfn></dt>
    <dd>
Render an ellipsis character (U+2026)
to represent clipped inline content.
Implementations may substitute a more language, script, or writing-mode appropriate
ellipsis character,
or three dots "..." if the ellipsis character is unavailable.
</dd>
</dl>

The term "character" is used in this property definition
for better readability and means "grapheme cluster" [[!UAX29]]
for implementation purposes.

For the ellipsis value
implementations must hide characters and
<a href="https://www.w3.org/TR/CSS2/visuren.html#inline-boxes">
atomic inline-level elements</a>
at the <a>end</a> edge of the line as necessary to fit the ellipsis, and
place the ellipsis immediately adjacent
to the <a>end</a> edge of the remaining inline content.
The first character or
<a href="https://www.w3.org/TR/CSS2/visuren.html#inline-boxes">
atomic inline-level element</a>
on a line
must be clipped rather than ellipsed.

<div class=example>
<h4 id="bidi-ellipsis" class="no-num no-toc">Bidi ellipsis examples</h4>
These examples demonstrate which characters get hidden
to make room for the ellipsis in a bidi situation:
those visually at the end edge of the line.

Sample CSS:
<pre><code highlight=css>
div {
  font-family: monospace;
  white-space: pre;
  overflow: hidden;
  width: 9ch;
  text-overflow: ellipsis;
}
</code></pre>

Sample HTML fragments, renderings, and your browser:
<table class="awesome-table data">
<thead><th>HTML<th>Reference rendering<th>Your Browser</thead>
<tr>
<td><code highlight=html>&lt;div>שלום 123456&lt;/div></code><td><div style="font-family:monospace">123456 ם…</div><td><div style="font-family: monospace; white-space: pre; overflow: hidden; width: 9ch; text-overflow: ellipsis">שלום 123456</div>
<tr><td><code highlight=html>&lt;div dir=rtl>שלום 123456&lt;/div></code><td><div style="font-family:monospace">…456 שלום</div><td><div style="font-family: monospace; white-space: pre; overflow: hidden; width: 9ch; text-overflow: ellipsis" dir=rtl>שלום 123456</div>

</table>


</div>

<h4 id="ellipsing-details" class="no-num no-toc">ellipsing details</h4>
<ul>
<li>
Ellipsing only affects rendering and must not affect layout
nor dispatching of pointer events:
The UA should dispatch any pointer event on the ellipsis to the elided element,
as if 'text-overflow' had been ''text-overflow/none''.
<li>
The ellipsis is styled and baseline-aligned according to
the block.
<li>
Ellipsing occurs after relative positioning and other graphical transformations.
<li>
If there is insufficient space for the ellipsis,
then clip the rendering of the ellipsis itself
(on the same side that neutral characters on the line
would have otherwise been clipped with the ''text-overflow:clip'' value).
</ul>

<h4 id="ellipsis-interaction" class="no-num no-toc">user interaction with ellipsis</h4>
<ul>
<li>When the user is interacting with content
(e.g. editing, selecting, scrolling),
the user agent may treat ''text-overflow: ellipsis'' as ''text-overflow: clip''.

<li>Selecting the ellipsis should select the ellipsed text.
If all of the ellipsed text is selected,
UAs should show selection of the ellipsis.
Behavior of partially-selected ellipsed text is up to the UA.

</ul>

<div class="example"><p style="display:none">Example(s):
<h4 id="text-overflow-examples" class="no-num no-toc">text-overflow examples</h4>

These examples demonstrate setting the text-overflow of a block container element
that has text which overflows its dimensions:

sample CSS for a div:
<pre><code class="lang-css">div {
  font-family:Helvetica,sans-serif; line-height:1.1;
  width:3.1em; padding:.2em; border:solid .1em black; margin:1em 0;
}</code></pre>

sample HTML fragments, renderings, and your browser:
<table class="awesome-table"><tbody>
<tr><th>HTML</th><th>sample rendering</th><th>your browser</th></tr>
<tr>
<td><pre><code class="lang-markup">&lt;div&gt;
CSS IS AWESOME, YES
&lt;/div&gt;
</code></pre></td>


<td>
<object type="image/png" data="images/cssisawesome.png">
First, a box with text drawing outside of it.
</object>
</td>

<td>
<div style="width:3.1em; border:solid .1em black; margin:1em 0; padding:.2em; font-family:Helvetica,sans-serif; line-height:1.1;">CSS IS AWESOME, YES</div>
</td>
</tr>

<tr>
<td><pre><code class="lang-markup">&lt;div style="<strong>text-overflow:clip;</strong> overflow:hidden"&gt;
CSS IS AWESOME, YES
&lt;/div&gt;
</code></pre></td>

<td>
<object type="image/png" data="images/cssisaweso.png">
Second, a similar box with the text clipped outside the box.
</object></td>

<td>
<div style="width:3.1em; border:solid .1em black; margin:1em 0; padding:.2em; font-family:Helvetica,sans-serif; line-height:1.1; overflow:hidden;text-overflow:clip;">CSS IS AWESOME, YES</div>
</td>
</tr>

<tr>
<td><pre><code class="lang-markup">&lt;div style="<strong>text-overflow:ellipsis;</strong> overflow:hidden"&gt;
CSS IS AWESOME, YES
&lt;/div&gt;
</code></pre></td>

<td>
<object type="image/png" data="images/cssisaw.png">
Third, a similar box with an ellipsis representing the clipped text.
</object>
</td>

<td>
<div style="width:3.1em; border:solid .1em black; margin:1em 0; padding:.2em;  font-family:Helvetica,sans-serif; line-height:1.1; overflow:hidden;text-overflow:ellipsis;">CSS IS AWESOME, YES</div>
</td>
</tr>


<tr>
<td><pre><code class="lang-markup">&lt;div style="<strong>text-overflow:ellipsis;</strong> overflow:hidden"&gt;
NESTED
 &lt;p&gt;PARAGRAPH&lt;/p&gt;
WON'T ELLIPSE.
&lt;/div&gt;
</code></pre></td>

<td>
<object type="image/png" data="images/nes.png">
Fourth, a box with a nested paragraph demonstrating anonymous block boxes equivalency and non-inheritance into a nested element.
</object>
</td>

<td>
<div style="width:3.1em; border:solid .1em black; margin:1em 0; padding:.2em;  font-family:Helvetica,sans-serif; line-height:1.1; overflow:hidden;text-overflow:ellipsis;">NESTED
 <p>PARAGRAPH</p>
WON'T ELLIPSE.</div>
</td>

</tr>
</tbody></table>

</div>

Note: the side of the line that the ellipsis is placed depends on the 'direction' of the block.
E.g. an overflow hidden right-to-left
(<code class="lang-css">direction: rtl</code>)
block clips inline content on the <a spec=css-writing-modes-3>left</a> side,
thus would place a text-overflow ellipsis on the <a spec=css-writing-modes-3>left</a>
to represent that clipped content.

<!-- insert RTL example diagram here to illustrate note. -->

<h4 id="ellipsis-scrolling" class="no-num no-toc">ellipsis interaction with scrolling interfaces</h4>

This section applies to elements with text-overflow other than ''text-overflow:clip''
(non-clip text-overflow)
and overflow:scroll.

When an element with non-clip text-overflow has overflow of scroll
in the inline progression dimension of the text,
and the browser provides a mechanism for scrolling
(e.g. a scrollbar on the element,
or a touch interface to swipe-scroll, etc.),
there are additional implementation details that provide a better user experience:

When an element is scrolled (e.g. by the user, DOM manipulation),
more of the element's content is shown.
The value of text-overflow should not affect
whether more of the element's content is shown or not.
If a non-clip text-overflow is set,
then as more content is scrolled into view,
implementations should show whatever additional content fits,
only truncating content which would otherwise be clipped
(or is necessary to make room for the ellipsis/string),
until the element is scrolled far enough
to display the edge of the content
at which point that content should be displayed
rather than an ellipsis/string.

<div class="example"><p style="display:none">Example(s):

This example uses text-overflow on an element with overflow scroll
to demonstrate the above described behavior.

sample CSS:
<pre><code class="lang-css">
div.crawlbar {
	text-overflow: ellipsis;
	height: 2em;
	overflow: scroll;
	white-space: nowrap;
	width: 15em;
	border:1em solid black;
}
</code></pre>

sample HTML fragment:
<pre><code class="lang-markup">
&lt;div class="crawlbar"&gt;
CSS is awesome, especially when you can scroll
to see extra text instead of just
having it overlap other text by default.
&lt;/div&gt;
</code></pre>

demonstration of sample CSS and HTML:
<div style="text-overflow: ellipsis; height: 2em; overflow: scroll; white-space: nowrap; width: 15em; border:1em solid black;">
CSS is awesome, especially when you can scroll
to see extra text instead of just
having it overlap other text by default.
</div>
</div> <!-- example -->

While the content is being scrolled, implementations may adjust their rendering of ellipses (e.g. align to the box edge rather than line edge).

<h3 id="block-ellipsis">
Indicating Block-Axis Overflow: the 'block-ellipsis' property</h3>

	<pre class=propdef>
		Name: block-ellipsis
		Value: none | auto | <<string>>
		Initial: none
		Applies to: [=block containers=]
		Inherited: yes
		Percentages: N/A
		Computed value: specified value
		Animation type: discrete
	</pre>

	This property allows inserting content into the last line box
	before a (forced <em>or</em> unforced) <a>region break</a>
	to indicate the continuity of truncated/interrupted content.
	It only affects line boxes contained directly by the <a>block container</a> itself,
	but as it inherits, will have an effect on descendants’ line boxes unless overridden.
	If the box contains no line box immediately preceding a <a>region break</a>,
	then this property has no effect.

	Note: See [[#fragmentation]] for a way to generate boxes with such a [=region break=].

	ISSUE: Should this apply to other types of fragmentation breaks (e.g. pages, columns)?

	The inserted content is called the <dfn>block overflow ellipsis</dfn>.
	Values have the following meanings:

	<dl dfn-for="block-ellipsis" dfn-type=value>
		<dt><dfn>none</dfn>
		<dd>
			The rendering is unaffected.

		<dt><dfn>auto</dfn>
		<dd>
			Render an ellipsis character (U+2026)--
			or a more typographically-appropriate equivalent--
			as the <a>block overflow ellipsis</a>
			at the end of the affected line box.
			UAs should use the conventions of the
			<a>content language</a>,
			writing system, and
			<a>writing mode</a>
			to determine the most appropriate ellipsis string.

		<dt><dfn><<string>></dfn>
		<dd>
			Render the specified string
			as the <a>block overflow ellipsis</a>
			at the end of the affected line box.
			The UA may truncate this string if it is absurdly long.
	</dl>

	When 'block-ellipsis' is not ''block-ellipsis/none'',
	the <a>block overflow ellipsis</a> string
	is wrapped in an anonymous inline
	and placed at the end of the line box
	as a direct child of the <a>block container</a>’s <a>root inline box</a>,
	reducing the space in the line box
	available to the other contents of the line.
	This inline is assigned ''unicode-bidi: plaintext''
	and ''line-height: 0''
	and is placed in the line box after the last
	<a>soft wrap opportunity</a> (see [[!CSS-TEXT-3]])
	that would still allow the entire <a>block overflow ellipsis</a> to fit on the line.
	For this purpose, <a>soft wrap opportunities</a> added by 'overflow-wrap' are ignored.
	If this results in the entire contents of the line box being displaced,
	the line box is considered to contain a [=strut=], as defined in [[CSS2/visudet.html#leading]].
	Text <a href="https://www.w3.org/TR/css-text-3/#justification">alignment and justification</a>
	occurs after placement,
	and measures the inserted <a>block overflow ellipsis</a>
	together with the rest of the line’s content.

	Note: Setting the [=block overflow ellipsis=]'s 'line-height' to ''0''
	makes sure that inserting it cannot cause the line's height to grow,
	which could cause further relayouts and potentially cycles.
	This is almost equivalent to inserting the [=block overflow ellipsis=]
	as a paint-time operation, except that it still participates in alignment and justification.
	The downside is that unusually tall / deep glyphs in the [=block overflow ellipsis=]
	may overflow.

	The [=block overflow ellipsis=] must not be included
	in either the ''::first-letter'' nor the ''::first-line'' pseudo-elements.

	If there is a subsequent <a>fragmentation container</a> in the [=fragmentation context=]
	that would receive subsequent content,
	then the content displaced by the <a>block overflow ellipsis</a>
	must be pushed to that <a>fragmentation container</a>.

	The UA must treat the <a>block overflow ellipsis</a> as an unbreakable string,
	If any part of the [=block overflow ellipsis=] overflows,
	it is treated as [=scrollable overflow=],
	and its rendering is affected by the 'text-overflow' property.

	The <a>block overflow ellipsis</a> does not capture events:
	pointer events are dispatched to whatever is underneath it.

	It also has no effect on the intrinsic size of the box:
	its <a lt="min-content size">min-content</a> and <a lt="max-content size">max-content</a> sizes
	are calculated exactly as if 'block-ellipsis' were ''block-ellipsis/none''.

	Note: Future specifications may extend this feature,
	for example by providing an ''::ellipsis'' pseudo-element
	to style the text,
	or by allowing the selection of a child element of the block
	to use as either an inline-level or block-level indicator
	(in which case, it can capture events).


<h2 id=fragmentation>
Fragmenting Overflow</h2>

<h3 id=line-clamp>
Limiting Visible Lines: the 'line-clamp' shorthand property</h3>

	<pre class="propdef shorthand">
		Name: line-clamp
		Value: none | <<integer>> <<'block-ellipsis'>>?
		Initial: none
		Percentages: N/A
	</pre>

	The 'line-clamp' property is a <a>shorthand</a>
	for the 'max-lines', 'block-ellipsis', and 'continue' properties.

	Issue: For the time being,
	experiemental implementations are encouraged
	to follow the full behavior defined by this shorthand and its longhands,
	but to only expose the shorthand to authors.
	This is in order to facilitate further tweaking,
	and in particular potential renaming,
	of the longhand properties and their values.

	It allows limiting the contents of a block container
	to the specified number of lines;
	remaining content is fragmented away
	and neither rendered nor measured.
	Optionally, it also allows inserting content into the last line box
	to indicate the continuity of truncated/interrupted content.

	The values have the following meaning:

	<dl dfn-for=line-clamp dfn-type=value>
		<dt><dfn>none</dfn>
		<dd>Sets 'max-lines' to ''max-lines/none'',
			'continue' to ''continue/auto'',
			and 'block-ellipsis' to ''block-ellipsis/none''.

		<dt><dfn><<integer>></dfn>
		<dd>Sets 'max-lines' to the specified <<integer>>,
			'continue' to ''discard'',
			and the 'block-ellipsis' property to second component of the value
			or to ''block-ellipsis/auto'' if omitted.

	</dl>

	See the corresponding longhand properties for details
	about how this mechanism operates.

	<div class="example">
		In this example, the lead paragraph of each article
		is listed in a shortened menu,
		truncated to fit within 10 lines
		that end with “… (continued on next page)”:

		<xmp highlight=css>
			li {
				line-clamp: 5 "… (continued on next page)";
			}
			strong {
				display: block;
				text-transform: uppercase;
			}
		</xmp>

		<xmp highlight=markup>
			<li><a href="cheese-is-milk">
				<strong>Cheese is Actually Made of Milk!</strong>
				Investigative reporters at the World Wide Web Press Corps
				have discovered the secret of cheese.
				Tracing through byzantine layers of bureacracy and shadow corporations,
				our crack team of journalists have traced the source of camembert.
			</a></li>
		</xmp>

		Sample rendering:

		<pre class="figure">
			+---------------------------------------+
			| CHEESE IS ACTUALLY MADE OF MILK!      |
			| Investigative reporters at the World  |
			| Wide Web Press Corps have discovered  |
			| the secret of cheese. Tracing through |
			| byzantine…  (continued on next page)  |
			+---------------------------------------+
		</pre>
	</div>

<h4 id=webkit-line-clamp>
Legacy compatibility</h4>

	For compatibility with legacy content,
	UAs that support 'line-clamp' must also support the <dfn dfn-type=property>-webkit-line-clamp</dfn> property.
	Like 'line-clamp', it is a shorthand of 'max-lines', 'continue', and 'block-ellipsis',
	except that:

	* its syntax is ''line-clamp/none'' | <<integer>>
	* it sets 'continue' to ''-webkit-discard'' instead of ''discard''
	* it unconditionally sets 'block-ellipsis' to ''block-ellipsis/auto''

	Additionally, for children (including anonymous children)
	of boxes whose 'display' property computes to ''-webkit-box'' or ''-webkit-inline-box'',
	the used values of the 'max-lines', 'continue', and 'block-ellipsis' properties
	are taken from the computed values of the parent box;
	the computed values of these properties on the box itself are ignored.

	The <dfn value for=continue>-webkit-discard</dfn> value behaves identically to ''discard'',
	except that it only takes effect
	if the computed value of the 'display' property on the parent
	is ''-webkit-box'' or ''-webkit-inline-box''
	and the computed value of the '-webkit-box-orient' property on the parent
	is ''-webkit-box-orient/vertical''.

	Note: Implementations of the legacy '-webkit-line-clamp' property
	have not behaved identically to what is specified here.
	The historical behavior is quirky and less robust,
	as documented for example in <a href="https://medium.com/mofed/css-line-clamp-the-good-the-bad-and-the-straight-up-broken-865413f16e5">this blog post</a>.
	The current design learns from the mistakes of that early experiment,
	and is intended to be sufficiently compatible with existing content
	that implementations can eventually be changed to follow to the specified behavior.
	If further adjustments are found to be necessary,
	they will be incorporated to this specification.
	In the meanwhile, authors should be aware that there may be discrepancies.

<h3 id="max-lines">
Forcing a Break After a Set Number of Lines: the 'max-lines' property</h3>

	<pre class=propdef>
		Name: max-lines
		Value: ''none'' | <<integer>>
		Initial: ''none''
		Applies to: <a>block containers</a> which are also [=fragmentation containers=] that capture [=region breaks=]
		Inherited: no
		Percentages: N/A
		Computed value: the keyword ''max-lines/none'' or an integer
		Animation type: by computed value type
	</pre>

	This property has no effect on boxes that are not [=fragmentation containers=] that capture [=region breaks=].

	Otherwise, if the value of 'max-lines' is not <dfn for=max-lines dfn-type=value>none</dfn>,
	a <a>region break</a>
	is forced after its <var>N</var>th
	descendant <a>in-flow</a> <a>line box</a>,
	where <var>N</var> is the specified value of 'max-lines'.
	Only lines boxes in the same <a>Block Formatting Context</a>
	are counted:
	the contents of descendants that establish <a>independent formatting contexts</a>
	are skipped over while counting line boxes.

	If fewer than <var>N</var> line boxes exist,
	then 'max-lines' introduces no <a>region break</a>.

	<div class=example>
		As ''continue: discard'' does not cause the element to [=establish an independent formatting context=],
		lines in a nested element with 'line-clamp' are counted,
		as can be seen in the examples below.
		<xmp highlight=markup>
			<div id=a>
				a: line 1<br>
				a: line 2<br>
				<div id=b>
					b: line 1<br>
					b: line 2<br>
					b: line 3<br>
					b: line 4<br>
				</div>
				a: line 3<br>
				a: line 4<br>
			</div>
		</xmp>
		Sample rendering given <code highlight=css>#a { line-clamp: 5; } b { line-clamp: 2; }</code>:
		<pre>
			a: line 1
			a: line 2
			b: line 1
			b: line 2…
			a: line 3…
		</pre>

		Sample rendering given <code highlight=css>#a { line-clamp: 3; } b { line-clamp: 2; }</code>:
		<pre>
			a: line 1
			a: line 2
			b: line 1…
		</pre>
		Note that in the second case,
		the maximum of 2 lines set on element ''#b'' does not take effect,
		since a forced break is introduced
		before the second line of this element.
	</div>

	Note: This implies that 'max-lines' has no effect when applied to [=multi-column containers=],
	since any line box they contain are nested into [=independent formatting contexts=].

	Only positive integers are accepted.
	Zero or negative integers are invalid
	and must cause the declaration to be <a>ignored</a>.

	Note: The 'widows', 'orphans', and 'break-inside' properties
	do not affect the position of the forced <a>region break</a>
	introduced by the 'max-lines' property.

	<div class=note>
		Note: Despite the “region break” name, this is not a dependency on [[CSS-REGIONS-1]].
		The word “region” is only used as a classifier for forced breaks:
		they can be “page breaks” (breaks across pages [[css-page-3]]),
		“column breaks” (breaks across multi-column layout columns [[css-multicol-1]]),
		or “region breaks” (breaks across any other kind of CSS-induced <a>fragmentation containers</a>).

		If an implementation supports neither [[CSS-REGIONS-1]] nor [[CSS-OVERFLOW-4#fragmentation]],
		then it will have had no occasion yet to run into that kind of breaks,
		and this will be an addition.
		However the addition does not involve bringing over any of the [[CSS-REGIONS-1]] functionality.
		All that is needed is:

		* be able to fragment
		* classify these fragmentation containers as “Category 3”
			(i.e. not pages nor columns)
			for the purpose of forced breaks.
	</div>

<h3 id="continue">
Fragmentation of Overflow: the 'continue' property</h3>

	<pre class=propdef>
		Name: continue
		Value: auto | discard
		Initial: ''continue/auto''
		Applies to: [=block containers=] and [=multicol containers=]
		Inherited: no
		Percentages: N/A
		Computed value: specified keyword
		Animation type: discrete
	</pre>

The 'continue' property gives authors the ability
to turn a box into a [=fragmentation container=] (see [[!CSS-BREAK-3]])
and to specify that content after the [=fragmentation break=] must be discarded.

Issue: This property is meant to generalize and replace the <code>region-fragment</code> property from [[CSS-REGIONS-1]].
Once it is sufficiently stable in this specification,
<code>region-fragment</code> should be removed from the regions specification in favor of this.

	<dl dfn-for="continue" dfn-type="value">
		<dt><dfn>auto</dfn>
		<dd>

			If the box has more content than can fit,
			the excess content is handled according to the usual rules.

		<dt><dfn>discard</dfn>
		<dd>
			The box becomes a [=fragmentation container=]
			that captures <a>region breaks</a>,
			if it is not already.
			[[!CSS-BREAK-3]]

			The position of the first <a lt="forced break">forced</a> [=region break=]
			(whether imposed by 'max-lines' or by another mechanism,
			such as the 'break-before'/'break-after' properties)
			or the position of the first [=unforced break=],
			which ever comes sooner,
			is treated as the end of the <a>fragmentation container</a>,
			and the remaining content after the [=fragmentation break=] is discarded,
			similar to if it were ''display: none'':
			* It is not rendered
			* Just as the content is visually hidden, it is not made available for speech rendering
			* It does not allow user interaction
			* Issue(2970): Make sure effects on OM are well defined
			* [=Positioned=] elements whose static position is in the discarded content are not rendered.

				Issue(2971): Are we sure about that?
				Discussions in the <a href="https://lists.w3.org/Archives/Public/www-style/2018Jul/0030.html">Syndey F2F meeting</a>
				seemed to generally converge on this,
				but other possibilities were raised.

			However, since intrinsic sizes are calculated across <a>fragmentation containers</a>,
			this content <em>is</em> taken into account
			for the purpose of finding the box’s
			<a lt="min-content inline size">min-content</a> and <a>max-content</a> <a>inline sizes</a>
			(see [[css-break-3#varying-size-boxes]]).
			<a lt="min-content inline size">Min-content</a> and <a>max-content</a> <a>block sizes</a>
			are calculated based on the content
			from the start of the [=fragmented flow=]
			to the first [=forced break=] if any,
			or to the end of the [=fragmented flow=] if there is no forced break.

			Note: Calculating intrinsic block sizes to the first forced <em>or unforced</em> break
			would cause intrinsic sizes to depend on layout, which would cause circularities.

			The effect on [=multi-column containers=] is to discard any [=overflow column=].

			Note: In the case of <a href="https://www.w3.org/TR/css-break-3/#parallel-flows">parallel fragmentation flows</a>,
			content occuring after the <a>fragmentation break</a> in the box tree
			could still be rendered,
			if it is laid out above the position
			representing the end of this <a>fragmentation container</a>.

	</dl>

	Note: This property does <em>not</em> cause the box to [=establish an independent formatting context=].

	<div class=example>
		Given an article with one excessively long overflowing line,
		and four more lines than can fit in the [=fragmentation direction=] as in the illustration bellow,
		different renderings are possible based on the combination of the 'overflow' and 'continue' property.

		<figure>
		<img src="images/continue-flow.png" alt="article with one excessively long line and four more that can fit in the block direction">
		</figure>


		<table class=data>
			<tr>
				<th>
				<th>''continue: discard''
				<th>''continue: auto''

			<tr>
				<th>''overflow: visible''

				<td style=vertical-align:top><img src="images/continue-discard-visible.png" alt=
				"rendering with continue:discard and overflow:visible"></td>

				<td><img src="images/continue-auto-visible.png"
				alt="rendering with continue:auto and overflow:visible"></td>
			</tr>

			<tr>
				<th>''overflow: hidden''

				<td><img src="images/continue-discard-hidden.png" alt=
				"rendering with continue:discard and overflow:hidden"></td>

				<td><img src="images/continue-auto-hidden.png"
				alt="rendering with continue:auto and overflow:hidden"></td>
			</tr>
		</table>

	</figure>
	</div>


Privacy and Security Considerations {#priv-sec}
===============================================

This specification introduces no new privacy or security concerns.

<h2 class=no-num id="acknowledgments">
Acknowledgments</h2>

	<p>
		Thanks especially to the feedback from
		Rossen Atanassov,
		Bert Bos,
		Tantek Çelik,
		John Daggett,
		Daniel Glazman,
		Vincent Hardy,
		H&aring;kon Wium Lie,
		Peter Linss,
		Robert O'Callahan,
		Florian Rivoal,
		Alan Stearns,
		Steve Zilles,
		and all the rest of the
		<a href="http://lists.w3.org/Archives/Public/www-style/">www-style</a> community.
