8000 csswg-drafts/css-text/Overview.bs at 40c591ec8de748d9af7dfcd0d445bf23a3cd1f26 · w3c/csswg-drafts · GitHub
Skip to content
7FFF

Latest commit

 

History

History
2338 lines (2022 loc) · 110 KB

File metadata and controls

2338 lines (2022 loc) · 110 KB
<h1>CSS Text Module Level 3</h1>
<pre class='metadata'>
Shortname: css-text
Level: 3
Status: ED
Work Status: Refining
Group: csswg
ED: https://drafts.csswg.org/css-text-3/
TR: https://www.w3.org/TR/css-text-3/
Previous Version: https://www.w3.org/TR/2013/WD-css-text-3-20131010/
Previous Version: https://www.w3.org/TR/2012/WD-css3-text-20121113/
!Issue Tracking: <a href="http://www.w3.org/Style/CSS/Tracker/products/10">http://www.w3.org/Style/CSS/Tracker/products/10</a>
Test Suite: http://test.csswg.org/suites/css3-text/nightly-unstable/
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
Editor: Koji Ishii, Invited Expert, kojiishi@gluesoft.co.jp
Abstract: This CSS3 module defines properties for text manipulation and specifies their processing model. It covers line breaking, justification and alignment, white space handling, and text transformation.
At Risk: the ''full-width'' value of 'text-transform'
At Risk: the &lt;length> values of the 'tab-size' property
At Risk: the 'text-justify' property
At Risk: the percentage values of 'word-spacing'
At Risk: the 'hanging-punctuation' property
Ignored Vars: letter-spacing
</pre>
<style type="text/css">
img { vertical-align: middle; }
span[lang] { font-size: 125%; line-height: 1; vertical-align: middle;}
/* Bidi & spaces example */
.egbidiwsaA,.egbidiwsbB,.egbidiwsaB,.egbidiwsbC
{ white-space:pre;font-size:80%;font-family:monospace; vertical-align:2px; margin:1px }
.egbidiwsaA { background:lime;padding:2px; }
.egbidiwsbB { border:2px solid blue }
.egbidiwsaB { background:yellow;border:2px dotted white }
.egbidiwsbC { border:2px dotted red }
.hyphens-ex {
border: thin solid black;
display: inline-block;
padding: 4pt;
}
/* Start Letter-spacing Tutorial */
.ls-ex {
font-size: 200%;
margin-left: 1em;
margin-right: 1em;
}
.ls-fixed-width {
width: 10em;
}
.color-box { background: rgb(224, 203, 82); }
.bad { color: red; }
.good { color: green; }
/* End Letter-spacing Tutorial */
.char { border: 1px dotted gray; }
.quarter { font-size: 25%; }
tt[lang="ja"] { font-family: "MS Gothic", "Osaka", monospace }
div.figure table {
margin :auto;
}
.feedback {
background: #FFEECC;
border-color: orange;
}
.feedback:before {
content: "Info Needed";
color: #FF8800;
}
.data .no { color: red; }
.data .ok { color: green; }
.data th em { display: block; font-size: smaller; font-weight: normal; font-style: italic; }
</style>
<h2 id="intro">
Introduction</h2>
<p>This module describes the typesetting controls of CSS;
that is, the features of CSS that control the translation of
source text to formatted, line-wrapped text.
Various CSS properties provide control over
<a href="#transforming">case transformation</a>,
<a href="#white-space">white space collapsing</a>,
<a href="#white-space">text wrapping</a>,
<a href="#line-breaking">line breaking rules</a>
and <a href="#hyphenation">hyphenation</a>,
<a href="#justification">alignment and justification</a>,
<a href="#spacing">spacing</a>,
and <a href="#edge-effects">indentation</a>.
<div class="note">
<p>Font selection is covered in <a href="https://www.w3.org/TR/css3-fonts/">CSS Fonts Level 3</a> [[CSS3-FONTS]].
<p>
<span id="decoration"></span>
<span id="text-decoration"></span>
<span id="line-decoration"></span>
<span id="text-decoration-line"></span>
<span id="text-decoration-color"></span>
<span id="text-decoration-style"></span>
<span id="text-decoration-skip"></span>
<span id="text-underline-position"></span>
<span id="emphasis-marks"></span>
<span id="text-emphasis-style"></span>
<span id="text-emphasis-color"></span>
<span id="text-emphasis"></span>
<span id="text-emphasis-position"></span>
<span id="text-shadow"></span>
Features for decorating text,
such as <a href="https://www.w3.org/TR/css-text-decor-3/#line-decoration">underlines</a>,
<a href="https://www.w3.org/TR/css-text-decor-3/#emphasis-marks">emphasis marks</a>,
and <a href="https://www.w3.org/TR/css-text-decor-3/#text-shadow-property">shadows</a>,
(previously part of this module)
are covered in
<a href="https://www.w3.org/TR/css-text-decor-3/">CSS Text Decoration Level 3</a> [[CSS3-TEXT-DECOR]].
<p><a href="https://www.w3.org/TR/css3-writing-modes/#text-direction">Bidirectional</a> and
<a href="https://www.w3.org/TR/css3-writing-modes/#vertical-intro">vertical</a> text
are addressed in
<a href="https://www.w3.org/TR/css3-writing-modes/">CSS Writing Modes Level 3</a> [[CSS3-WRITING-MODES]].
</div>
<h3 id="placement">
Module Interactions</h3>
<p>This module, together with [[CSS3-TEXT-DECOR]],
replaces and extends the text-level features defined in [[!CSS21]] chapter 16.
<h3 id="values">
Values</h3>
<p>This specification follows the
<a href="https://www.w3.org/TR/CSS21/about.html#property-defs">CSS property
definition conventions</a> from [[!CSS21]]. Value types not defined in
this specification are defined in CSS Level 2 Revision 1 [[!CSS21]].
Other CSS modules may expand the definitions of these value types: for
example [[CSS3VAL]], when combined with this module, expands the
definition of the <<length>> value type as used in this specification.</p>
<p>In addition to the property-specific values listed in their definitions,
all properties defined in this specification also accept the
<a href="https://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a>
keyword as their property value. For readability it has not been repeated
explicitly.
<h3 id="terms">
Terminology</h3>
<p>In addition to the terms defined below,
other terminology and concepts used in this specification are defined
in [[!CSS21]] and [[!CSS3-WRITING-MODES]].
<h4 id="characters">
Characters and Letters</h4>
<p>The basic unit of typesetting is the <dfn export>character</dfn>.
However, because writing systems are not always as simple as the basic English alphabet,
what a <a>character</a> actually is depends on the context in which the term is used.
For example, in Hangul (the Korean writing system),
each square representation of a syllable
(e.g. <span lang=ko-hang title="Hangul syllable HAN">한</span>=<span lang=ko-Latn>Han</span>)
can be considered a <a>character</a>.
However, the square symbol is really composed of multiple letters each representing a phoneme
(e.g. <span lang=ko-hang title="Hangul letter HIEUH">ㅎ</span>=<span lang=ko-Latn>h</span>,
<span lang=ko-hang title="Hangul letter HIEUH">ㅏ</span>=<span lang=ko-Latn>a</span>,
<span lang=ko-hang title="Hangul letter HIEUH">ㄴ</span>=<span lang=ko-Latn>n</span>)
and these also could each be considered a <a>character</a>.
<p>A basic unit of computer text encoding, for any given encoding,
is also called a <a>character</a>,
and depending on the encoding,
a single encoding <a>character</a> might correspond
to the entire pre-composed syllabic <a>character</a> (e.g. <span lang=ko-hang title="Hangul syllable HAN">한</span>),
to the individual phonemic <a>character</a> (e.g. <span lang=ko-hang title="Hangul letter HIEUH">ㅎ</span>),
or to smaller units such as
a base letterform (e.g. <span lang=ko-hang title="Hangul letter IEUNG">ㅇ</span>)
and any combining marks that vary it (e.g. extra strokes that represent aspiration).
<p>In turn, a single encoding <a>character</a> can be represented in the data stream as one or more bytes;
and in programming environments one byte is sometimes also called a <a>character</a>.
<p>Therefore the term <a>character</a> is fairly ambiguous where technical precision is required.
<p>For text layout, we will refer to the <dfn export lt="typographic character unit|typographic character">typographic character unit</dfn>
as the basic unit of text.
Even within the realm of text layout,
the relevant <a>character</a> unit depends on the operation.
For example, line-breaking and letter-spacing will segment
a sequence of Thai characters that include U+0E33 THAI CHARACTER SARA AM differently;
or the behaviour of a conjunct consonant in a script such as Devanagari
may depend on the font in use.
So the <a>typographic character</a> represents a unit of the writing system&mdash;<!--
-->such as a Latin alphabetic letter (including its diacritics),
Hangul syllable,
Chinese ideographic character,
Myanmar syllable cluster&mdash;<!--
-->that is indivisible with respect to a particular typographic operation
(line-breaking, first-letter effects, tracking, justification, vertical arrangement, etc.).
<a href="http://www.unicode.org/reports/tr29/">Unicode Standard Annex #29: Text Segmentation</a>
defines a unit called the <dfn>grapheme cluster</dfn>
which approximates the <a>typographic character</a>.
A UA must use the <em>extended grapheme cluster</em>
(not <em>legacy grapheme cluster</em>), as defined in [[!UAX29]],
as the basis for its <a>typographic character unit</a>.
However, the UA should tailor the definitions
as required by typographic tradition
since the default rules are not always appropriate or ideal--
and is expected to tailor them differently
depending on the operation as needed.
<p class="note">
The rules for such tailorings are out of scope for CSS.
<!--
however W3C currently maintains a wiki page
where some known tailorings are collected.
-->
<div class="example">
The following are some examples of <a>typographic character unit</a> tailorings
required by standard typesetting practice:
<ul>
<li>
<p>In some scripts such as Myanmar or Devanagari,
the <a>typographic character unit</a> for both justification and line-breaking
is an entire syllable,
which can include more than one [[!UAX29]] <a>grapheme cluster</a>.
<li>
<p>In other scripts such as Thai or Lao,
even though for line-breaking the <a>typographic character</a>
matches Unicode’s default <a>grapheme clusters</a>,
for letter-spacing the relevant unit
is <em>less</em> than a [[!UAX29]] <a>grapheme cluster</a>,
and may require decomposition or other substitutions
before spacing can be inserted.
<p>For instance,
to properly letter-space the Thai word คำ (U+0E04 + U+0E33),
the U+0E33 needs to be decomposed into U+0E4D + U+0E32,
and then the extra letter-space inserted before the U+0E32: คํ า.
<p>A slightly more complex example is น้ำ (U+0E19 + U+0E49 + U+0E33).
In this case, normal Thai shaping will first decompose the U+0E33 into U+0E4D + U+0E32
and then swap the U+0E4D with the U+0E49, giving U+0E19 + U+0E4D + U+0E49 + U+0E32.
As before the extra letter-space is then inserted before the U+0E32: นํ้ า.
<li>
<p>Vertical typesetting [[!CSS3-WRITING-MODES]] can also require tailoring.
For example, when typesetting ''text-orientation/upright'' text,
Tibetan tsek and shad marks are kept with the preceding grapheme cluster,
rather than treated as an independent <a>typographic character unit</a>.
</ul>
</div>
<p>A <dfn export>typographic letter unit</dfn> or <dfn>letter</dfn> for the purpose of this specification
is a <a>typographic character unit</a> belonging to one of the Letter or Number general
categories in Unicode. [[!UAX44]]
See <a href="#character-properties">Character Properties</a>
for how to determine the Unicode properties of a <a>typographic character unit</a>.
<p>The rendering characteristics of a <a>typographic character unit</a> divided
by an element boundary is undefined:
it may be rendered as belonging to either side of the boundary,
or as some approximation of belonging to both.
Authors are forewarned that dividing <a>grapheme clusters</a>
by element boundaries may give inconsistent or undesired results.
<h4 id="languages">
Languages and Typesetting</h4>
<p class="note">
Many typographic effects vary by linguistic context.
In CSS, language-specific typographic tailorings
are only applied when the content language is known (declared).
<p><strong class="advisement">
Authors should language-tag their content accurately for the best typographic behavior.
</strong>
<p>The <dfn export>content language</dfn> of an element is the (human) language
the element is declared to be in, according to the rules of the
<a href="https://www.w3.org/TR/CSS21/conform.html#doclanguage">document language</a>.
For example, the rules for determining the <a>content language</a> of an HTML
element use the <code>lang</code> attribute and are defined in [[HTML5]],
and the rules for determining the <a>content language</a> of an XML element use
the <code>xml:lang</code> attribute and are
<a href="https://www.w3.org/TR/REC-xml/#sec-lang-tag">defined</a> in [[XML10]].
Note that it is possible for the <a>content language</a> of an element
to be unknown.
<h2 id="transforming">
Transforming Text</h2>
<h3 id="text-transform-property">
<span id="caps-prop"></span>
<span id="text-transform"></span>
Case Transforms: the 'text-transform' property</h3>
<pre class="propdef">
Name: text-transform
Value: none | capitalize | uppercase | lowercase | full-width
Initial: none
Inherited: yes
Canonical order: n/a
</pre>
<p>This property transforms text for styling purposes.
(It has no effect on the underlying content.)
Values have the following meanings:</p>
<dl dfn-for=text-transform dfn-type=value>
<dt><dfn>none</dfn></dt>
<dd>No effects.</dd>
<dt><dfn>capitalize</dfn></dt>
<dd>Puts the first <a>typographic letter unit</a> of each word in titlecase;
other characters are unaffected.</dd>
<dt><dfn>uppercase</dfn></dt>
<dd>Puts all <a>letters</a> in uppercase.
<dt><dfn>lowercase</dfn></dt>
<dd>Puts all <a>letters</a> in lowercase.</dd>
<dt><dfn>full-width</dfn></dt>
<dd>Puts all <a>typographic character units</a> in fullwidth form.
If a character does not have a corresponding fullwidth form,
it is left as is.
This value is typically used to typeset Latin letters and digits
as if they were ideographic characters.
</dl>
<p>For ''capitalize'', what constitutes a “word“ is UA-dependent;
[[!UAX29]] is suggested (but not required) for determining such word
boundaries. Authors should not expect ''capitalize'' to follow
language-specific titlecasing conventions (such as skipping articles
in English).
<div class="example">
<p>The following example converts the ASCII characters
used in abbreviations in Japanese text to their fullwidth variants
so that they lay out and line break like ideographs:
<pre>abbr:lang(ja) { text-transform: full-width; }</pre>
</div>
<p class="note">
Note that, as defined in <a href="#order">Text Processing Order of Operations</a>,
transforming text affects line-breaking and other formatting operations.
<p>
The UA must use the full case mappings for Unicode
characters, including any conditional casing rules, as defined in
Default Case Algorithm section of The Unicode Standard [[!UNICODE]].
If (and only if) the <a>content language</a>
of the element is, according to the rules of the
<a href="https://www.w3.org/TR/CSS21/conform.html#doclanguage">document language</a>,
known,
then any appropriate language-specific rules must be applied as well.
These minimally include, but are not limited to, the language-specific
rules in Unicode's
<a href="http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt">SpecialCasing.txt</a>.
<div class="example">
<p>For example, in Turkish there are two &ldquo;i&rdquo;s, one with
a dot&mdash;&ldquo;İ&rdquo; and &ldquo;i&rdquo;&mdash; and one
without&mdash;&ldquo;I&rdquo; and &ldquo;ı&rdquo;. Thus the usual
case mappings between &ldquo;I&rdquo; and &ldquo;i&rdquo; are
replaced with a different set of mappings to their respective
undotted/dotted counterparts, which do not exist in English. This
mapping must only take effect if the <a>content language</a> is Turkish
(or another Turkic language that uses Turkish casing rules);
in other languages, the usual mapping of &ldquo;I&rdquo;
and &ldquo;i&rdquo; is required. This rule is thus conditionally
defined in Unicode's SpecialCasing.txt file.
</div>
<p>The definition of fullwidth and halfwidth forms can be found on the
Unicode consortium web site at [[!UAX11]].
The mapping to fullwidth form is defined by taking code points with
the <code>&lt;wide&gt;</code> or the <code>&lt;narrow&gt;</code> tag
in their <code>Decomposition_Mapping</code> in [[!UAX44]].
For the <code>&lt;narrow&gt;</code> tag,
the mapping is from the code point to the decomposition (minus <code>&lt;narrow&gt;</code> tag),
and for the <code>&lt;wide&gt;</code> tag,
the mapping is from the decomposition (minus the <code>&lt;wide&gt;</code> tag)
back to the original code point.
<p>Text transformation happens after <a href="#white-space-rules">white
space processing</a>, which means that ''full-width'' only transforms
U+0020 spaces to U+3000 within <a>preserved</a> white space.
<p class="note">
A future level of CSS may introduce the ability to create custom mapping
tables for less common text transforms, such as by an ''@text-transform''
rule similar to ''@counter-style'' from [[CSS-COUNTER-STYLES-3]].
<h2 id="white-space-property">
<span id="white-space-collapsing"></span><span id='text-wrap'></span>
White Space and Wrapping: the 'white-space' property</h2>
<pre class="propdef">
Name: white-space
Value: normal | pre | nowrap | pre-wrap | pre-line
Initial: normal
Applies to: all elements
Inherited: yes
Canonical order: n/a
</pre>
<p>This property specifies two things:
<ul>
<li>whether and how <a>white space</a> inside the element is collapsed
<li>whether lines may <a>wrap</a> at unforced <a>soft wrap opportunities</a>
</ul>
<p>Values have the following meanings, which must be interpreted
according to
the <a href="#white-space-rules">White Space Processing</a> and
<a href="#line-breaking">Line Breaking</a> rules:</p>
<dl dfn-for=white-space dfn-type=value>
<dt><dfn>normal</dfn></dt>
<dd>This value directs user agents to collapse sequences of <a>white space</a>
into a single character (or <a href="#line-break-transform">in some
cases</a>, no character).
Lines may wrap at allowed <a>soft wrap opportunities</a>,
as determined by the line-breaking rules in effect,
in order to minimize inline-axis overflow.
<dt><dfn>pre</dfn></dt>
<dd>This value prevents user agents from collapsing sequences of <a>white space</a>.
<a>Segment breaks</a> such as line feeds and carriage returns are preserved as <a>forced line breaks</a>.
Lines only break at <a>forced line breaks</a>;
content that does not fit within the block container overflows it.
<dt><dfn>nowrap</dfn>
<dd>Like ''white-space/normal'', this value collapses <a>white space</a>;
but like ''pre'', it does not allow wrapping.
<dt><dfn>pre-wrap</dfn></dt>
<dd>Like ''pre'', this value preserves <a>white space</a>;
but like ''white-space/normal'', it allows wrapping.
<dt><dfn>pre-line</dfn></dt>
<dd>Like ''white-space/normal'', this value collapses consecutive spaces and allows wrapping,
but preserves <a>segment breaks</a> in the source as <a>forced line breaks</a>.
</dl>
<p>The following informative table summarizes the behavior of various
'white-space' values:</p>
<table class="data">
<colgroup class="header"></colgroup>
<colgroup span=3></colgroup>
<thead>
<tr>
<th></th>
<th>New Lines</th>
<th>Spaces and Tabs</th>
<th>Text Wrapping</th>
</tr>
</thead>
<tbody>
<tr>
<th>''white-space/normal''</th>
<td>Collapse</td>
<td>Collapse</td>
<td>Wrap</td>
</tr>
<tr>
<th>''pre''</th>
<td>Preserve</td>
<td>Preserve</td>
<td>No wrap</td>
</tr>
<tr>
<th>''nowrap''</th>
<td>Collapse</td>
<td>Collapse</td>
<td>No wrap</td>
</tr>
<tr>
<th>''pre-wrap''</th>
<td>Preserve</td>
<td>Preserve</td>
<td>Wrap</td>
</tr>
<tr>
<th>''pre-line''</th>
<td>Preserve</td>
<td>Collapse</td>
<td>Wrap</td>
</tbody>
</table>
<p>See <a href="#white-space-processing">White Space Processing Rules</a>
for details on how white space collapses. An informative summary of
collapsing (''white-space/normal'' and ''nowrap'') is presented below:
<ul>
<li>A sequence of segment breaks and other <a>white space</a> between two
Chinese, Japanese, or Yi characters collapses into nothing.
<li>A zero width space before or after a white space sequence
containing a segment break causes the entire sequence of <a>white space</a>
to collapse into a zero width space.
<li>Otherwise, consecutive <a>white space</a> collapses into a single space.
</ul>
<p>See <a href="#line-breaking">Line Breaking</a>
for details on wrapping behavior.
<h2 id="white-space-processing">
White Space Processing Details</h2>
<p>The source text of a document often contains formatting
that is not relevant to the final rendering: for example,
<a href="http://rhodesmill.org/brandon/2012/one-sentence-per-line/"
>breaking the source into segments</a> (lines) for ease of editing
or adding white space characters such as tabs and spaces to indent the source code.
CSS white space processing allows the author to control interpretation of such formatting:
to preserve or collapse it away when rendering the document.
White space processing in CSS interprets white space characters only for rendering:
it has no effect on the underlying document data.
<p>White space processing in CSS is controlled with the 'white-space' property.
<p id="segment-normalization">
CSS does not define document segmentation rules. Segments can be
separated by a particular newline sequence (such as a line feed or
CRLF pair), or delimited by some other mechanism, such as the SGML
<code>RECORD-START</code> and <code>RECORD-END</code> tokens.
For CSS processing, each document language&ndash;defined segment break,
CRLF sequence (U+000D U+000A), carriage return (U+000D), and line feed (U+000A)
in the text is treated as a <dfn export>segment break</dfn>,
which is then interpreted for rendering as specified by the 'white-space' property.
<p class="note">Note that a document parser might
not only normalize any <a>segment breaks</a>,
but also collapse other space characters or
otherwise process white space according to markup rules.
Because CSS processing occurs <em>after</em> the parsing stage,
it is not possible to restore these characters for styling.
Therefore, some of the behavior specified below
can be affected by these limitations and
may be user agent dependent.</p>
<p class="note">Note that anonymous blocks consisting entirely of
<a>collapsible</a> <a>white space</a> are removed from the rendering tree.
Thus any such <a>white space</a> surrounding a block-level element is collapsed away.
See [[CSS21]] section
<a href="https://www.w3.org/TR/CSS21/visuren.html#anonymous">9.2.2.1</a></p>
<p>
Control characters (<a>Unicode category</a> <code>Cc</code>)
other than tab (U+0009), line feed (U+000A), form feed (U+000C), and carriage return (U+000D)
must be rendered as a visible glyph
and otherwise treated as any other character
of the Other Symbols (<code>So</code>) <a>general category</a> and Common <a lt="Unicode script">script</a>.
The UA may use a glyph provided by a font specifically for the control character,
substitute the glyphs provided for the corresponding symbol in the Control Pictures block,
generate a visual representation of its codepoint value,
or use some other method to provide an appropriate visible glyph.
As required by [[!UNICODE]],
unsupported <code>Default_ignorable</code> characters must be ignored for rendering.
<h3 id="white-space-rules">
The White Space Processing Rules</h3>
<p>White space processing in CSS affects only
the <dfn export lt="white space|white space characters| document white space|document white space characters">document white space characters</dfn>:
spaces (U+0020), tabs (U+0009), and <a href="#white-space-processing">segment breaks</a>.
<p class="note">
Note that the set of characters considered <a>document white space</a> (part of the document content)
and that considered syntactic white space (part of the CSS syntax)
are not necessarily identical.
However, since both include spaces (U+0020), tabs (U+0009), line feeds (U+000A), and carriage returns (U+000D)
most authors won't notice any differences.
<h4 id="white-space-phase-1">Phase I: Collapsing and Transformation</h4>
<p>For each inline (including anonymous inlines;
see [[CSS21]] section <a href="https://www.w3.org/TR/CSS21/visuren.html#anonymous">9.2.2.1</a>)
within an inline
formatting context, white space characters are handled as follows,
ignoring bidi formatting characters as if they were not there:</p>
<ul>
<li id="collapse"><p>If 'white-space' is set to
''white-space/normal'', ''nowrap'', or ''pre-line'',
white space characters are considered <dfn export lt="collapsible white space|collapsible">collapsible</dfn>
and are processed by performing the following steps:</p>
<ol>
<li>All spaces and tabs immediately preceding or following a segment
break are removed.</li>
<li><a>Segment breaks</a> are transformed for
rendering according to the <a href="#line-break-transform">segment break transformation rules</a>.
</li>
<li>Every tab is converted to a space (U+0020).</li>
<li>Any space immediately following another collapsible space&mdash;even
one outside the boundary of the inline containing that space,
provided both spaces are within the same inline formatting
context&mdash;is collapsed to have zero advance width. (It is
invisible, but retains its <a>soft wrap opportunity</a>, if any.)</li>
</ol>
</li>
<li><p>If 'white-space' is set to ''pre'' or ''pre-wrap'',
any sequence of spaces is treated as a sequence of non-breaking spaces.
However, a <a>soft wrap opportunity</a> exists at the end of the sequence.
<p>Then, the entire block is rendered. Inlines are laid out, taking bidi
reordering into account, and <a>wrapping</a> as specified by the
'white-space' property.</p>
<div class="example" id="egbidiwscollapse">
<p>The following example illustrates
the interaction of white-space collapsing and bidirectionality.
Consider the following markup fragment, taking special note of spaces
(with varied backgrounds and borders for emphasis and identification):
<pre><code>&lt;ltr&gt;A<span class="egbidiwsaA">&#160;</span>&lt;rtl&gt;<span class="egbidiwsbB">&#160;</span>B<span class="egbidiwsaB">&#160;</span>&lt;/rtl&gt;<span class="egbidiwsbC">&#160;</span>C&lt;/ltr&gt;</code></pre>
<p>where the <code>&lt;ltr&gt;</code> element represents a left-to-right embedding
and the <code>&lt;rtl&gt;</code> element represents a right-to-left embedding.
If the 'white-space' property is set to ''white-space/normal'',
the white-space processing model will result in the following:
<ul style="line-height:1.3">
<li>The space before the B (<span class="egbidiwsbB">&#160;</span>)
will collapse with the space after the A (<span class="egbidiwsaA">&#160;</span>).
<li>The space before the C (<span class="egbidiwsbC">&#160;</span>)
will collapse with the space after the B (<span class="egbidiwsaB">&#160;</span>).
</ul>
<p>This will leave two spaces,
one after the A in the left-to-right embedding level,
and one after the B in the right-to-left embedding level.
The text will then be ordered according to the Unicode bidirectional algorithm,
with the end result being:
<pre>A<span class="egbidiwsaA">&#160;</span><span class="egbidiwsaB">&#160;</span>BC</pre>
<p>Note that there will be two spaces between A and B,
and none between B and C.
This is best avoided by putting spaces outside the element
instead of just inside the opening and closing tags and, where practical,
by relying on implicit bidirectionality instead of explicit embedding levels.
</div>
<h4 id="line-break-transform">
Segment Break Transformation Rules</h4>
<p>When 'white-space' is ''pre'', ''pre-wrap'', or ''pre-line'',
<a>segment breaks</a> are not <a>collapsible</a>
and are instead transformed into a preserved line feed (U+000A).
<p>For other values of 'white-space', <a>segment breaks</a> are <a>collapsible</a>,
and are either transformed into a space (U+0020) or removed
depending on the context before and after the break:</p>
<ul>
<li>If the character immediately before or immediately after the segment
break is the zero-width space character (U+200B), then the break
is removed, leaving behind the zero-width space.
<li>Otherwise, if the <a>East Asian Width property</a> [[!UAX11]] of both
the character before and after the line feed is <code>F</code>, <code>W</code>, or <code>H</code> (not <code>A</code>),
and neither side is Hangul, then the segment break is removed.
<li>Otherwise, the segment break is converted to a space (U+0020).
</ul>
<p class="note">Note that the white space processing rules have already
removed any tabs and spaces after the segment break before these checks
take place.</p>
<p class="feedback issue">Comments on how well this would work in practice would
be very much appreciated, particularly from people who work with
Thai and similar scripts.
Note that browser implementations do not currently follow these rules
(although IE does in some cases transform the break).</p>
<h4 id="white-space-phase-2">Phase II: Trimming and Positioning</h4>
<p>As each line is laid out,</p>
<ol>
<li>A sequence of collapsible spaces at the beginning of a line is
removed.
<li>If the tab size is zero, tabs are not rendered.
Otherwise, each tab is rendered as a horizontal shift
that lines up the start edge of the next glyph with the next <a>tab stop</a>.
<dfn lt="tab stop">Tab stops</dfn> occur at points that are multiples of the tab size
from the block's starting content edge.
The tab size is given by the 'tab-size' property.
<li>A sequence of <a>collapsible</a> spaces at the end of a line is removed.
<li>If spaces or tabs at the end of a line are non-collapsible
but have 'white-space' set to ''pre-wrap''
the UA must either <a>hang</a> the <a>white space</a>
or visually collapse the character advance widths
of any overflowing spaces
such that they don't take up space in the line.
However, if 'overflow-wrap' is set to ''break-spaces'',
collapsing their advance width is not allowed,
as this would prevent the preserved spaces from wrapping.
Note: Hanging the white space rather than collapsing it
allows users to see the space when selecting or editing text.
</ol>
Issue: Add example of hanging white space + same example right-aligned.
<p>White space that was not removed or collapsed during the white space
processing steps is called <dfn>preserved</dfn> white space.</p>
<h3 id="tab-size-property">
Tab Character Size: the 'tab-size' property</h3>
<pre class="propdef">
Name: tab-size
Value: <<integer>> | <<length>>
Initial: 8
Applies to: block containers
Inherited: yes
Computed value: the specified integer or length made absolute
Animation type: <a href="https://drafts.csswg.org/css-transitions-1/#animtype-length">length</a>
Canonical order: n/a
</pre>
<p>This property determines the tab size used to render preserved tab characters (U+0009).
Integers represent the measure as multiples of the space character's advance width (U+0020).
Negative values are not allowed.
<h2 id="line-breaking">
Line Breaking and Word Boundaries</h2>
<p>When inline-level content is laid out into lines, it is broken across line boxes.
Such a break is called a <dfn>line break</dfn>.
When a line is broken due to explicit line-breaking controls,
or due to the start or end of a block,
it is a <dfn>forced line break</dfn>.
When a line is broken due to content <dfn lt="wrapping|wrap">wrapping</dfn>
(i.e. when the UA creates unforced line breaks in order to fit the content within the measure),
it is a <dfn>soft wrap break</dfn>.
The process of breaking inline-level content into lines is called <dfn lt="line-breaking-process">line breaking</dfn>.
<p>Wrapping is only performed at an allowed break point, called a <dfn export>soft wrap opportunity</dfn>.
<p>In most writing systems,
in the absence of hyphenation a <a>soft wrap opportunity</a> occurs only at word boundaries.
Many such systems use spaces or punctuation to explicitly separate words,
and <a>soft wrap opportunities</a> can be identified by these characters.
Scripts such as Thai, Lao, and Khmer, however,
do not use spaces or punctuation to separate words.
Although the zero width space (U+200B) can be used as an explicit word delimiter in these scripts,
this practice is not common.
As a result, a lexical resource is needed to correctly identify <a>soft wrap opportunities</a> in such texts.
<p>In several other writing systems, (including Chinese, Japanese, Yi, and sometimes also Korean)
a <a>soft wrap opportunity</a> is based on syllable boundaries, not word boundaries.
In these systems a line can break anywhere <em>except</em> between certain character combinations.
Additionally the level of strictness in these restrictions can vary with the typesetting style.</p>
<p>CSS does not fully define where <a>soft wrap opportunities</a> occur;
however some controls are provided to distinguish common variations.
<div class="note">
<p>Further information on line breaking conventions can be found in
[[JLREQ]] and [[JIS4051]] for Japanese,
[[ZHMARK]] for Chinese, and
in [[!UAX14]] for all scripts in Unicode.
<p class="feedback issue">Any guidance for appropriate references here would be
much appreciated.
</div>
<h3 id="line-break-details">
Line Breaking Details</h3>
<p>When determining <a>line breaks</a>:
<ul>
<li>Regardless of the 'white-space' value,
lines always break at each <a>preserved</a> forced break character:
for all values, line-breaking behavior defined for
the BK, CR, LF, CM, NL, and SG line breaking classes in [[!UAX14]]
must be honored.
<li>When 'white-space' allows wrapping,
line breaking behavior defined for the WJ, ZW, and GL line-breaking classes in [[!UAX14]]
must be honored.
<li>UAs that allow wrapping at punctuation other than spaces should prioritize breakpoints.
For example, if breaks after slashes are given a lower priority than spaces,
the sequence "check /etc" will never break between the "/" and the "e".
As long as care is taken to avoid such awkward breaks, allowing breaks at
appropriate punctuation other than spaces is recommended, as it results
in more even-looking margins, particularly in narrow measures.
The UA may use the width of the containing block, the text's language,
and other factors in assigning priorities.
<li>Out-of-flow elements do not introduce a <a>forced line break</a>
or <a>soft wrap opportunity</a> in the flow.
<li>The line breaking behavior of a replaced element or other atomic inline
is equivalent to an ideographic character
(Unicode linebreaking class <code>ID</code> [[!UAX14]]),
and additionally, for Web-compatibility, introduces a <a>soft wrap opportunity</a>
between itself and any adjacent U+00A0 NO-BREAK SPACE character.
<li>For <a>soft wrap opportunities</a> created by characters that disappear at the line break (e.g. U+0020 SPACE),
properties on the element containing that character control the line breaking at that opportunity.
For <a>soft wrap opportunities</a> defined by the boundary between two characters,
the properties on nearest common ancestor of the two characters controls breaking.
<!-- http://lists.w3.org/Archives/Public/www-style/2008Dec/0043.html -->
<li>For <a>soft wrap opportunities</a> before the first or after the last character of a box,
the break occurs immediately before/after the box (at its margin edge)
rather than breaking the box between its content edge and the content.
<li>Line breaking in/around Ruby is defined in <a href="https://www.w3.org/TR/css-ruby-1/#line-breaks">CSS Ruby</a> [[!CSS3RUBY]].
</ul>
<h3 id="word-break-property">
Breaking Rules for Letters: the 'word-break' property</h3>
<pre class="propdef">
Name: word-break
Value: normal | keep-all | break-all
Initial: normal
Inherited: yes
Canonical order: n/a
</pre>
<p>This property specifies <a>soft wrap opportunities</a> between letters,
i.e. where it is “normal” and permissible to break lines of text.
It does not affect rules governing the <a>soft wrap opportunities</a>
created by spaces and punctuation.
(See 'line-break' for controls affecting punctuation.)
<div class="example">
<p>For example, in some styles of CJK typesetting, English words are allowed
to break between any two letters, rather than only at spaces or hyphenation points;
this can be enabled with ''word-break:break-all''.
<div class="figure">
<img src="images/break-all.png" alt="A snippet of Japanese text with English in it. The word 'caption' is broken into 'capt' and 'ion' across two lines.">
<p class="caption">An example of English text embedded in Japanese
being broken at an arbitrary point in the word.
</div>
<p>As another example, Korean has two styles of line-breaking:
between any two Korean syllables (''word-break: normal'')
or, like English, mainly at spaces (''word-break: keep-all'').
<pre>각 줄의 마지막에 한글이 올 때 줄 나눔 기 /* break between syllables */
<!-- -->준을 “글자” 또는 “어절” 단위로 한다.</pre>
<pre>각 줄의 마지막에 한글이 올 때 줄 나눔 /* break only at spaces */
<!-- -->기준을 “글자” 또는 “어절” 단위로 한다.</pre>
</div>
<p class="note">
To enable additional break opportunities only in the case of overflow,
see 'overflow-wrap'.
<p>Values have the following meanings:</p>
<dl dfn-for=word-break dfn-type=value>
<dt><dfn>normal</dfn></dt>
<dd>Words break according to their customary rules,
as described <a href="#line-breaking">above</a>.
Korean, which commonly exhibits two different behaviors,
allows breaks between any two consecutive Hangul/Hanja.
<dt><dfn>break-all</dfn></dt>
<dd>Breaking is allowed within “words”:
in addition to ''word-break/normal'' <a>soft wrap opportunities</a>:
specifically, any <a>typographic character units</a> resolving to the
<code>NU</code> (“numeric”), <code>AL</code> (“alphabetic”), or <code>SA</code> (“Southeast Asian”)
line breaking classes [[!UAX14]]
are instead treated as <code>ID</code> (“ideographic characters”)
for the purpose of line-breaking.
Hyphenation is not applied. This option is used mostly in a context where
the text consists predominantly of CJK characters with only short non-CJK excerpts,
and it is desired that the text be better distributed on each line.</dd>
<dt><dfn>keep-all</dfn></dt>
<dd>Breaking is forbidden within “words”:
implicit <a>soft wrap opportunities</a> between <a>typographic letter units</a> are suppressed,
i.e. breaks are prohibited between pairs of letters
(regardless of 'line-break' settings)
except where opportunities exist due to dictionary-based breaking.
Otherwise this option is equivalent to ''word-break/normal''.
In this style, sequences of CJK characters do not break.
<p class=note>This is the other common behavior for Korean (which uses spaces between words),
and is also useful for mixed-script text where CJK snippets are mixed
into another language that uses spaces for separation.</dd>
</dl>
<p>Symbols that line-break the same way as letters of a particular category
are affected the same way as those letters.
<div class="example">
<p>Here's a mixed-script sample text:
<pre>这是一些汉字, and some Latin,<!--
--> &#x0648; &#x06A9;&#x0645;&#x06CC; &#x0646;&#x0648;&#x0634;&#x062A;&#x0646; &#x0639;&#x0631;&#x0628;&#x06CC;, <!--
-->และตัวอย่างการเขียนภาษาไทย.</pre>
<p>The break-points are determined as follows (indicated by &lsquo;&middot;&rsquo;):
<dl>
<dt>''word-break: normal''</dt>
<dd>
<pre>这·是·一·些·汉·字,·and·some·Latin,<!--
-->·&#x0648;·&#x06A9;&#x0645;&#x06CC;·&#x0646;&#x0648;&#x0634;&#x062A;&#x0646;·&#x0639;&#x0631;&#x0628;&#x06CC;,·<!--
-->และ·ตัวอย่าง·การเขียน·ภาษาไทย.</pre>
<dt>''word-break: break-all''</dt>
<dd>
<pre>这·是·一·些·汉·字,·a·n·d·s·o·m·e·L·a·t·i·n,<!--
-->·&#x0648;·&#xFB90;·&#xFEE4;·&#xFEF0;·&#xFEE7;·&#xFEEE;·&#xFEB7;·&#xFE98;·&#xFEE6;·&#xFECB;·&#xFEAE;·&#xFE91;·&#xFEF0;,·<!--
-->แ·ล·ะ·ตั·ว·อ·ย่·า·ง·ก·า·ร·เ·ขี·ย·น·ภ·า·ษ·า·ไ·ท·ย.</pre>
<dt>''word-break: keep-all''</dt>
<dd>
<pre>这是一些汉字,·and·some·Latin,<!--
-->·&#x0648;·&#x06A9;&#x0645;&#x06CC;·&#x0646;&#x0648;&#x0634;&#x062A;&#x0646;·&#x0639;&#x0631;&#x0628;&#x06CC;,·<!--
-->แและ·ตัวอย่าง·การเขียน·ภาษาไทย.</pre>
</dl>
</div>
<p>When shaping scripts such as Arabic are allowed to break within words
due to ''break-all'', the characters must still be shaped as if the
word were not broken.</p>
<h3 id="line-break-property">
Breaking Rules for Punctuation: the 'line-break' property</h3>
<pre class="propdef">
Name: line-break
Value: auto | loose | normal | strict
Initial: auto
Inherited: yes
Canonical order: n/a
</pre>
<p>This property specifies the strictness of line-breaking rules applied
within an element:
particularly how <a>wrapping</a> interacts with punctuation and symbols.
Values have the following meanings:</p>
<dl dfn-for=line-break dfn-type=value>
<dt><dfn>auto</dfn></dt>
<dd>The UA determines the set of line-breaking restrictions to use,
and it may vary the restrictions based on the length of the line; e.g.,
use a less restrictive set of line-break rules for short lines.
<dt><dfn>loose</dfn></dt>
<dd>Breaks text using the least restrictive set of line-breaking
rules. Typically used for short lines, such as in newspapers.</dd>
<dt><dfn>normal</dfn></dt>
<dd>Breaks text using the most common set of line-breaking rules.</dd>
<dt><dfn>strict</dfn></dt>
<dd>Breaks text using the most stringent set of line-breaking
rules.</dd>
</dl>
<p class="feedback issue">
The rules here are following guidelines from <a href="https://www.w3.org/TR/klreq/#line-break">KLREQ</a> for Korean,
which don't allow the Chinese/Japanese-specific breaks.
However, the resulting behavior could use some review and feedback to make sure they are correct,
particularly when “word basis” breaking is used (''word-break: keep-all'') in Korean.
<p>CSS distinguishes between three levels of strictness in the rules for
text wrapping.
The precise set of rules in effect for each level is up to the UA
and should follow language conventions.
However, this specification does require that:</p>
<ul>
<li>
The following breaks are forbidden in ''strict'' line breaking
and allowed in ''line-break/normal'' and ''loose'':
<ul>
<li>breaks before Japanese small kana or the Katakana-Hiragana prolonged sound mark:
i.e. characters with the Unicode Line Break property <code>CJ</code>.
(See <a href="http://www.unicode.org/Public/UNIDATA/LineBreak.txt">LineBreak.txt</a> in [[!UNICODE]].)
</ul>
<li>
The following breaks are allowed for ''line-break/normal'' and ''loose'' line breaking
if the <a>content language</a> is Chinese or Japanese,
and are otherwise forbidden:
<ul>
<li>breaks before hyphens:<br>
&#x2010;&nbsp;U+2010, &#x2013;&nbsp;U+2013, &#x301C;&nbsp;U+301C,
&#x30A0;&nbsp;U+30A0
</ul>
<li>
The following breaks are forbidden for ''line-break/normal'' and ''strict'' line breaking
and allowed in ''loose'':
<ul>
<li>breaks before iteration marks:<br>
&#x3005;&nbsp;U+3005, &#x303B;&nbsp;U+303B, &#x309D;&nbsp;U+309D,
&#x309E;&nbsp;U+309E, &#x30FD;&nbsp;U+30FD, &#x30FE;&nbsp;U+30FE
<li>breaks between inseparable characters
such as &#x2025;&nbsp;U+2025, &#x2026;&nbsp;U+2026
i.e. characters with the Unicode Line Break property <code>IN</code>.
(See <a href="http://www.unicode.org/Public/UNIDATA/LineBreak.txt">LineBreak.txt</a> in [[!UNICODE]].)
</ul>
<li>
The following breaks are allowed for ''loose''
if the <a>content language</a> is Chinese or Japanese
and are otherwise forbidden:
<ul>
<li>breaks before certain centered punctuation marks:<br>
&#x30FB;&nbsp;U+30FB,
&#xFF1A;&nbsp;U+FF1A, &#xFF1B;&nbsp;U+FF1B, &#xFF65;&nbsp;U+FF65,
&#x203C;&nbsp;U+203C,
&#x2047;&nbsp;U+2047, &#x2048;&nbsp;U+2048, &#x2049;&nbsp;U+2049,
&#xFF01;&nbsp;U+FF01, &#xFF1F;&nbsp;U+FF1F
<li>breaks before suffixes:<br>