8000 csswg-drafts/css-inline-3/Overview.bs at 829a0748de7848bd071fec1942c2f11d0d515983 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1682 lines (1374 loc) · 61.1 KB

File metadata and controls

1682 lines (1374 loc) · 61.1 KB
<style media="print" type="text/css">
img#edge { width: 80%; height: 70%;}
dt.label { display: run-in; }
</style>
<pre class='metadata'>
Title: CSS Inline Layout Module Level 3
Shortname: css-inline
Level: 3
Status: WD
Work Status: Revising
Group: csswg
TR: https://www.w3.org/TR/css-inline-3/
ED: https://drafts.csswg.org/css-inline-3/
Previous version: https://www.w3.org/TR/2018/WD-css-inline-3-20180808/
Previous version: https://www.w3.org/TR/20 CB9A 16/WD-css-inline-3-20160524/
Previous version: https://www.w3.org/TR/2015/WD-css-inline-3-20150917/
Previous version: https://www.w3.org/TR/2014/WD-css-inline-3-20141218/
Previous version: https://www.w3.org/TR/2002/WD-css3-linebox-20020515/
!Issues list: <a href="https://github.com/w3c/csswg-drafts/issues?q=is%3Aissue+is%3Aopen+label%3Acss-inline-3">CSS3 Line Layout issues in GitHub</a>
Editor: Dave Cramer, Hachette Livre, dauwhe@gmail.com, w3cid 65283
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Steve Zilles, Adobe, szilles@adobe.com, w3cid 3129
Abstract: The CSS formatting model provides for a flow of elements and text inside of a container to be wrapped into lines. The formatting of elements and text within a line, its positioning in the inline progression direction, and the breaking of lines are described in [[CSS3TEXT]]. This module describes the positioning in the block progression direction both of elements and text within lines and of the lines themselves. This positioning is often relative to a baseline. It also describes special features for formatting of first lines and drop caps. It extends on the model in [[CSS2]].
Ignored Terms: line-height-shift-adjustment, text-script, after, before, alignment subtree
Link Defaults: css-fonts-3 (property) font-family, css-color-3 (property) color
At Risk: the 'initial-letters-wrap' property
</pre>
<pre class="link-defaults">
spec:css-align-3; type:dfn; text:alignment baseline
spec:css-break-3; type:dfn; text:fragment
</pre>
<h2 id="intro">
Introduction</h2>
This module defines the CSS Inline Layout model,
replacing and extending the model as defined in CSS2.1.
It is very much a work-in-progress, and implementers should reference CSS2.1 for now.
The <dfn export>root inline box</dfn> is an anonymous inline box
which is automatically generated to hold
all of the <a>inline-level</a> contents of a <a>block container</a>
(if it has any).
It inherits from its parent <a>block container</a>,
but is otherwise unstyleable.
Note: Line boxes, like <a>column boxes</a> [[css-multicol-1]],
are <a>fragmentation containers</a> generated by their <a>formatting context</a>
and are not part of the CSS <a>box tree</a>.
<h2 id="line-height">
Line Heights and Baseline Alignment</h2>
<p class="issue">This section is being rewritten. Refer to <a href="https://www.w3.org/TR/CSS2/visudet.html#line-height">section 10.8</a> of [[CSS2]] for the normative CSS definition or the <a href="https://www.w3.org/TR/2002/WD-css3-linebox-20020515/">2002 Working Draft</a> if you want pretty pictures. (But ignore the old text, half of it's wrong. We're not specifying which half, that's to be determined.)
<strong>The CSS2 specification should be used as the guideline for implementation.</strong></p>
Issue: The CSSWG would like to know which baseline values are necessary: if any can be dropped, or any need to be added. See GitHub issue <a href="https://github.com/w3c/csswg-drafts/issues/859">859</a>.
<h3 id="dominant-baseline-property">
Dominant Baselines: the 'dominant-baseline' property</h3>
<pre class="propdef">
Name: dominant-baseline
Value: auto | text-bottom | alphabetic | ideographic | middle | central | mathematical | hanging | text-top
Initial: normal
Applies to: block containers, inline boxes, table rows, table columns, grid containers, and flex containers
Inherited: yes
Percentages: N/A
Computed value: as specified
</pre>
This property specifies the <dfn>dominant baseline</dfn>,
which is the baseline used to align the box's text and inline-level contents.
It is also indicates the default <a>alignment baseline</a>
of any boxes participating in <a>baseline alignment</a>
in the box’s <a>alignment context</a>.
Values have the following meanings:
<dl dfn-for=dominant-baseline dfn-type=value>
<dt><dfn>auto</dfn>
<dd>
Equivalent to ''dominant-baseline/alphabetic'' in <a>horizontal writing modes</a>
and in <a>vertical writing modes</a>
when 'text-orientation' is ''sideways'', ''sideways-right'', or ''sideways-left''.
Equivalent to ''dominant-baseline/central'' in <a>vertical writing modes</a>
when 'text-orientation' is ''mixed'' or ''upright''.
However, in SVG text, the origin point of glyphs
(used for coordinate-based glyph positioning)
is always handled as for ''dominant-baseline/central''
in <a>vertical writing modes</a>.
<dt><dfn>text-bottom</dfn>
<dd>
Use the bottom of the em box as the baseline.
<dt><dfn>alphabetic</dfn>
<dd>
Use the alphabetic baseline.
<dt><dfn>ideographic</dfn>
<dd>
Match the box's ideographic character face under-side baseline to that of its parent.
<dt><dfn>middle</dfn>
<dd>
Use the “middle” baseline: halfway between the alphabetic baseline and the ex-height.
<dt><dfn>central</dfn>
<dd>
Use the central baseline
(halfway between the ascent and descent).
<dt><dfn>mathematical</dfn>
<dd>
Use the mathematical baseline.
<dt><dfn>hanging</dfn>
<dd>
Use the hanging baseline.
<dt><dfn>text-top</dfn>
<dd>
Use the top of the em box as the baseline.
</dl>
See [[CSS3-WRITING-MODES]] for an introduction to dominant baselines.
Issue: Should be text-over and text-under instead of text-top and text-bottom,
but maybe it's better not to use those terms for consistency with legacy 'vertical-align'.
See GitHub issue <a href="https://github.com/w3c/csswg-drafts/issues/860">860</a>.
Issue: Add <css>first</css> and <css>last</css> values.
Note, in this property, these are combinatorial,
whereas in the <css>align/justify-self/content</css> properties, it's singular.
Do we want to align the syntaxes wrt hyphens vs. spaces or what?
See GitHub issue <a href="https://github.com/w3c/csswg-drafts/issues/861">861</a>.
<h3 id="transverse-alignment">
Transverse Box Alignment: the 'vertical-align' property</h3>
<pre class="propdef">
Name: vertical-align
Value: <<'baseline-shift'>> || <<'alignment-baseline'>>
Initial: baseline
Applies to: inline-level boxes
Inherited: no
Percentages: N/A
Computed value: as specified
</pre>
<p>This shorthand property specifies how an inline-level box is aligned within the line.
Values are the same as for its longhand properties, see below.
<p class="advisement">
Authors should use this property ('vertical-align') instead of its longhands.
ISSUE: This property will gain ''first'' and ''last'' keywords,
like in the <a href="https://www.w3.org/TR/css-align-3/">box alignment properties</a>,
see [[css-align-3#baseline-values]].
The <a href="https://github.com/w3c/csswg-drafts/issues/861">open question</a>
is whether they should be added to 'alignment-baseline'
or a new <a>sub-property</a> should be created
to hold the ''first | last'' preference.
<h4 id="alignment-baseline-property">
Alignment Point: 'alignment-baseline' longhand</h4>
<pre class="propdef">
Name: alignment-baseline
Value: baseline | text-bottom | alphabetic | ideographic | middle | central | mathematical | text-top | bottom | center | top
Initial: baseline
Applies to: inline-level boxes, flex items, grid items, table cells
Inherited: no
Percentages: N/A
Computed value: as specified
</pre>
<p>Specifies what point of an inline-level box is aligned to what point in the parent.
Also selects the <a>alignment baseline</a> of boxes aligned with 'align-self'/'justify-self'.
ISSUE: Clean up this prose to correctly handle alignment contexts other than inline formatting contexts.
Values are defined below:
For the following definitions,
the margin box is used for atomic inlines,
the leading box for non-replaced inlines,
and the baselines of the box are <a lt="synthesized baseline">synthesized</a> if missing in the line-box's inline axis:
<dl dfn-for=alignment-baseline dfn-type=value>
<dt><dfn>baseline</dfn>
<dd>
Use the <a>dominant baseline</a> choice of the parent.
Match the box's corresponding baseline to that of its parent.
<dt><dfn>text-bottom</dfn>
<dd>
Match the bottom of the box to the bottom of the parent's content area.
<dt><dfn>alphabetic</dfn>
<dd>
Match the box's alphabetic baseline to that of its parent.
<dt><dfn>ideographic</dfn>
<dd>
Match the box's ideographic character face under-side baseline to that of its parent.
<dt><dfn>middle</dfn>
<dd>
Align the vertical midpoint of the box with
the baseline of the parent box plus half the x-height of the parent.
<dt><dfn>central</dfn>
<dd>
Match the box's central baseline to the central baseline of its parent.
<dt><dfn>mathematical</dfn>
<dd>
Match the box's mathematical baseline to that of its parent.
<dt><dfn>text-top</dfn>
<dd>
Match the top of the box to the top of the parent's content area.
</dl>
For the following definitions, the <a>alignment subtree</a>
is as defined in [[!CSS2]].
<dl dfn-for=alignment-baseline dfn-type=value>
<dt><dfn>top</dfn>
<dd>
Align the top of the aligned subtree with the top of the line box.
<dt><dfn>center</dfn>
<dd>
Align the center of the aligned subtree with the center of the line box.
<dt><dfn>bottom</dfn>
<dd>
Align the bottom of the aligned subtree with the bottom of the line box.
</dl>
SVG implementations <em>may</em> support the following aliases
in order to support legacy content:
<pre dfn-for=alignment-baseline dfn-type=value>
<dfn>text-before-edge</dfn> = ''alignment-baseline/text-top''
<dfn>text-after-edge</dfn> = ''alignment-baseline/text-bottom''
</pre>
These values are not allowed in the 'vertical-align' shorthand.
<h4 id="baseline-shift-property">
Alignment Shift: 'baseline-shift' longhand</h4>
<pre class="propdef">
Name: baseline-shift
Value: <<length>> | <<percentage>> | sub | super
Initial: 0
Applies to: inline-level boxes, flex items, grid items
<!-- table cells left out b/c CSS2.1 vertical-align values must have no effect... -->
Inherited: no
Percentages: refer to the used value of 'line-height'
Computed value: absolute length, percentage, or keyword specified
</pre>
<p>This property specifies by how much the box is shifted up
from its alignment point.
It does not apply when 'alignment-baseline' is ''alignment-baseline/top'' or ''alignm 8026 ent-baseline/bottom''.
<p class="advisement">
Authors should use the 'vertical-align' shorthand instead of this property.
Values have the following meanings:
<dl dfn-for="baseline-shift" dfn-type=value>
<dt><dfn><<length>></dfn>
<dd>Raise (positive value) or lower (negative value) by the specified length.
<dt><dfn><<percentage>></dfn>
<dd>Raise (positive value) or lower (negative value) by the specified percentage of the 'line-height'.
<dt><dfn>sub</dfn>
<dd>Lower by the offset appropriate for subscripts of the parent’s box.
(The UA should use the parent’s font data to find this offset whenever possible.)
<dt><dfn>super</dfn>
<dd>Raise by the offset appropriate for superscripts of the parent’s box.
(The UA should use the parent’s font data to find this offset whenever possible.)
</dl>
<p>User agents <em>may</em> additionally support the keyword <dfn for=baseline-shift>baseline</dfn>
as computing to ''0''
if is necessary for them to support legacy SVG content.
Issue: We would prefer to remove this, and are looking for feedback from SVG user agents as to whether it's necessary.
<h2 id="inline-box-dimensions">
Drawing Inline Boxes</h2>
<h3 id="line-fill">
Inline Box Heights: the 'inline-sizing' property</h3>
<pre class="propdef">
Name: inline-sizing
Value: normal | stretch
Initial: normal
Applies to: <a>inline boxes</a>
Inherited: no
Percentages: n/a
Computed value: as specified
</pre>
This property specifies how the <a>logical height</a>
of the <a>content area</a> of an <a>inline box</a>
is measured
and how it is aligned with its contents.
(It has no effect on the size or position of the box’s contents.)
Values have the following meanings:
<dl dfn-for="inline-sizing" dfn-type=value>
<dt><dfn>normal</dfn>
<dd>
The <a>content area</a> of the <a>inline box</a>
is sized and position to fit its (possibly hypothetical) text
as specified in <a href="https://www.w3.org/TR/CSS2/visudet.html#inline-non-replaced">CSS2&sect;10.6.1</a>.
<dt><dfn>stretch</dfn>
<dd>
The <a>logical height</a> of the <a>content area</a>
is calculated as the <a>stretch fit</a>
into the line box.
The box is then positioned such that its <a>margin edges</a>
coincide with the line box’s edges.
</dl>
Issue: We might want to use this opportunity to more precisely define ''inline-sizing/normal'',
rename it to match,
and possibly introduce any other values that may seem necessary.
<h2 id="initial-letter-styling">
<!--<a name="Initial"></a>-->
Initial Letters</h2>
<p class="issue">The editors would appreciate any examples of drop initials in non-western scripts, especially Arabic and Indic scripts.</p>
<h3 id="initial-letter-intro">
<!--<a name="DropInitial"></a>-->
An Introduction to Initial Letters</h3>
<em>This section is non-normative.</em>
Large, decorative letters have been used to start new sections of text since before the invention of printing.
In fact, their use predates lowercase letters entirely.
<h4 id="drop-initial">
Drop Initial</h4>
A <dfn>dropped initial</dfn> (or “drop cap”)
is a larger-than-usual letter at the start of a paragraph,
with a baseline at least one line lower than the first baseline of the paragraph.
The size of the drop initial is usually indicated by how many lines it occupies.
Two- and three-line drop initials are very common.
<figure>
<img src="images/Dropcap-E-acute-3line.png" width="480"
alt="3-line drop cap with E Acute" >
<figcaption>
Three-line drop initial with E acute.
Since the cap-height of the drop initial aligns with the cap-height of the main text,
the accent extends above the paragraph.
</figcaption>
</figure>
The exact size and position of a <a>dropped initial</a>
depends on the alignment of its glyph.
Reference points on the drop cap must align precisely
with reference points in the text.
The alignment constraints for drop initials depend on the writing system.
In Western scripts, the top reference points are
the cap height of the initial letter and of the first line of text.
The bottom reference points are
the alphabetic baseline of the initial letter
and the baseline of the Nth line of text.
<a href="#f2">Figure 2</a> shows a simple two-line drop cap, with the relevant reference lines marked.
<figure id="f2">
<img src="images/Dropcap-lines.png" width="600"
alt="drop cap showing alignment">
<figcaption>Two-line drop cap showing baselines (green lines), cap-height (red line), and ascender (cyan line).</figcaption>
</figur 4B74 e>
In Han-derived scripts, the initial letter extends
from the <a>block-start</a> edge of the glyphs on the first line
to the <a>block-end</a> edge of the glyphs on the Nth line.
<figure>
<img src="images/Initial-2line-JapaneseVertical六.png" width="480"
alt="Japanese Vertical Initial">
<figcaption>Two-line drop initial in vertical writing mode</figcaption>
</figure>
In certain Indic scripts,
the top alignment point is the hanging baseline,
and the bottom alignment point is the text-after-edge.
<figure>
<img src="images/Devangari-Initial.png" width="480"
alt="Devangari initial letter">
<figcaption>Devangari <a>initial letter</a> aligned with hanging baseline. Alignment points shown in red.</figcaption>
</figure>
<h4 id="sunk-initial">
Sunken Initial Letters</h4>
Some styles of drop initials do not align with the first line of text.
A <dfn>sunken initial</dfn> (or “sunken cap”)
both sinks below the first baseline,
and extends above the first line of text.
<figure>
<img src="images/SunkenCapA.png" width="480"
alt="sunken drop initial">
<figcaption>Sunken cap. The letter drops two lines, but is the size of a three-line initial letter.</figcaption>
</figure>
<h4 id="raise-initial">
Raised Initial Letters</h4>
A <dfn>raised initial</dfn> (often called a “raised cap” or “stick-up cap”) “sinks” to the first text baseline.
Note: A proper raised initial has several advantages over
simply increasing the font size of a first letter.
The line spacing in the rest of the paragraph will not be altered,
but text will still be excluded around large descenders.
And if the size of raised initial is defined to be an integral number of lines,
implicit baseline grids can be maintained.
<figure>
<img src="images/RaisedCap.png" width="480"
alt="raised cap">
<figcaption>Raised cap. The initial letter is the size of a 3-line initial, but does not drop.</figcaption>
</figure>
<h3 id="selecting-drop-initials">Selecting Initial Letters</h3>
Initial letters are typically a single letter, although
they may include punctuation or a sequence of characters which
are perceived by the user to be a single typographic unit.
The <code>::first-letter</code> pseudo-element, as defined in [[SELECT]],
can be used to select the character(s) to be formatted as <a>initial letters</a>.
Authors who need more control over which characters are included in an initial letter,
or who want to apply initial-letters formatting to replaced elements or multiple words
can alternately apply the 'initial-letters' property to the first inline-level child of a block container.
<div class="example">
<pre>
&lt;p>This paragraph has a dropped “T”.
&lt;p>&lt;img alt="H" src="illuminated-h.svg">ere we have an illuminated “H”.
&lt;p>&lt;span>Words may also&lt;/span> be given initial letter styling at the beginning of a paragraph.
</pre>
<pre>
::first-letter, /* style first paragraph's T */
img, /* style illuminated H */
span /* style phrase inside span */
{ initial-letters: 2; }
</pre>
</div>
<h4 id="initial-letter-punctuation">Initial Letter Punctuation</h4>
Since ''::first-letter'' selects punctuation before or after the first letter,
these characters are included in the initial-letters when ''::first-letter'' is used.
<figure>
<img src="images/initial-letter-punctuation-quote.png" width="604"
alt="Paragraph showing both opening quote and first letter set as three-line drop cap">
<figcaption>The <code>::first-letter</code> pseudo-element selects the quotation mark as well as the “M.”</figcaption>
</figure>
Issue: Should there be a way to opt out of this behavior? See <a href="https://github.com/w3c/csswg-drafts/issues/310">Github Issue 310</a>.
<h3 id="sizing-drop-initials">
Creating Initial Letters: the 'initial-letters' property</h3>
<pre class="propdef">
Name: <dfn id="propdef-initial-letters">initial-letters</dfn>
Value: normal | [<<number>> <<integer>>?]
Initial: normal
Applies to: certain inline-level boxes and <css>::first-letter</css> and inside <css>::marker</css> boxes (<a href="#first-most-inline-level">see prose</a>)
Inherited: no
Percentages: N/A
Computed value: as specified
</pre>
ISSUE: Renaming this property (and the others in this section)
is currently <a href="https://github.com/w3c/csswg-drafts/issues/2950">under discussion</a>.
This property specifies styling for dropped, raised, and sunken initial letters.
It takes the following values:
<dl dfn-for=initial-letters dfn-type=value>
<dt><dfn>normal</dfn>
<dd>
No special initial-letters effect. Text behaves as normal.
<dt><dfn><<number>></dfn>
<dd>
This first argument defines the <dfn dfn lt="initial letter size">size</a>
of the initial letter
in terms of how many lines it occupies.
Values less than one are invalid.
<dt><dfn><<integer>></dfn>
<dd>
This optional second argument
defines the number of lines the initial letter should
<dfn dfn lt="initial letter sink" local-lt="sink">sink</dfn>.
A value of ''1'' indicates a <a>raised initial</a>;
values greater than ''1'' indiciate a <a>sunken initial</a>.
Values less than one are invalid.
If omitted, it duplicates the first argument,
floored to the nearest positive whole number.
</dl>
An <dfn lt="initial letter | initial letter box">initial letter</dfn> is
an <a>in-flow</a> box
to which 'initial-letters' applies and is not ''initial-letters/normal'';
this triggers the special layout considerations described below.
<div class="example">
Here are some examples of 'initial-letters' usage:
<dl>
<dt>''initial-letters: 3''
<dt>(''initial-letters: 3 3'')
<dd>
Represents a <a>dropped initial</a> 3 lines high, 3 lines deep.
<img src="images/InitialLetter33.png" width="360"
alt="3 lines high, 3 lines deep">
<dt>''initial-letters: 3 2''
<dd>
Represents a <a>sunken initial</a> 3 lines high, 2 lines deep.
<img src="images/InitialLetter32.png" width="360"
alt="3 lines high, 2 lines deep">
<dt>''initial-letters: 3 1''
<dd>
Represents a <a>raised initial</a> 3 lines high, 1 line deep.
<img src="images/InitialLetter31.png" width="360"
alt="3 lines high, 1 line deep">
<dt>''initial-letters: 2.51 3''
<dd>
The size of the initial letter does not have to be an integral number of lines.
In this case only the bottom aligns.
<img src="images/non-integer-initial.png" width="360"
alt="Non-integral initial letter that only aligns at base">
</dl>
</div>
<div class="example">
The following code will create a 2-line dropped initial letter at the beginning of each paragraph:
<pre>p::first-letter { initial-letters: 2; }</pre>
</div>
<h4 id="first-most-inline-level">
Applicability</h4>
To give authors more control over which characters can be styled as an <a>initial letter</a>
and to allow the possibility of multi-character <a>initial letters</a>
(such as for first word or first phrase styling),
the 'initial-letters' property applies not just
to the CSS-defined ''::first-letter'' pseudo-element,
but also to
''list-style-position/inside''-positioned ''::marker'' pseudo-elements and
inline-level boxes
that are placed at the start of the first line.
Specifically, 'initial-letters' applies to
any <a>inline-level box</a>--
including any such ''::first-letter'' or ''::marker'' box--
that is the first child of its parent box
and whose ancestors (if any) that are descendants of its <a>containing block</a>
are all first-child <a>inline boxes</a>
that have a <a lt="computed value">computed</a> 'initial-letters' value
of ''initial-letters/normal''.
<div class="example">
For example,
the <code>&lt;span></code>, <code>&lt;em></code>, and <code>&lt;b></code> elements
in the following example are
"first-most inline-level descendants" of the <code>&lt;p></code>,
but the <code>&lt;strong></code> element
is not:
<xmp>
<p><span><em><b>This phrase</b> is styled</em> <strong>specially</strong>. &hellip;</span>
</xmp>
If we apply the following rules:
<pre>
em { initial-letters: 2; }
b { initial-letters: 3; }
</pre>
The result might be rendered as
<pre>
[ADD RENDERING HERE]
THIS PHRASE IS STYLED specially. &hellip;
</pre>
(Note that the styling on <code>&lt;b></code>
is ignored,
as it has an ancestor already styled as an <a>initial letter</a>.)
</div>
If 'initial-letters' is applied to an <a>inline-level box</a>
that is not positioned at the start of the line due to bidi reordering
or which is otherwise preceded by other <a>inline-level</a> content,
its <a>used value</a> is ''initial-letters/normal'',
and it is not formatted as an <a>initial letter</a>.
Note: The 'initial-letters' property cannot apply to any element
whose 'float' is not ''float/none'' or 'position' is not ''static'',
because these values cause its 'display' to compute to ''display/block''.
The effect of the 'initial-letters' property is undefined
on children of <a>ruby</a> base container boxes
and on <a>ruby</a> container boxes.
<h4 id="initial-letter-properties">
Properties</h4>
All properties that apply to an <a>inline box</a>
also apply to an <a>initial letter</a>
(unless it is an <a>atomic inline</a>,
in which case the set of properties that apply to an <a>atomic inline</a> apply)
except for 'vertical-align' and its <a>sub-properties</a>,
'font-size', and 'line-height'.
<!-- Basically, any properties defined in css-inline
except those specific to initial letters,
so keep this list updated as we add things to this spec. -->
Additionally, all of the <a>sizing properties</a>
and 'box-sizing' also apply to <a>initial letters</a>.
<h4 id="initial-letter-model">
Layout Model</h4>
An <a>initial letter</a> is laid out following the steps outlined below:
<ol>
<li>
Find the used font size based on its 'initial-letters' size,
'initial-letters-align' alignment points,
and font metrics.
Note that no layout is required in this step.
The font size used for sizing the <a>initial letter</a> contents
<em>does not</em> affect its computed 'font-size' property
(and therefore has no effect on the computation of ''em'' length values, etc.).
<li>
Size the <a>initial letter</a>’s content box.
If its <a>width</a>/<a>height</a> is definite,
use that value
(clamped as required by the <a>min size</a> and <a>max size</a> properties,
and handling 'box-sizing' as required)
for that dimension of the box.
In the case of a definite <a>inline size</a>,
'text-align' is honored
for aligning the contents of the <a>initial letter</a> within its box
in the <a>inline axis</a>
(using its <a>inline-axis</a> bearings as usual,
not the bounding box of its glyph outlines).
In the case of a definite <a>block size</a>,
'align-content' is honored
for aligning its contents in the <a>block axis</a>
(using its <a>block-axis</a> bearings,
synthesizing them if needed).
Otherwise
it is considered to have an <a>automatic size</a> in that dimension
and is sized and positioned to coincide with
the smallest rectangle that would include
the bounding boxes of all its glyphs--
excluding any that <a spec="css-text-3">hang</a>
(see 'hanging-punctuation')--
as well as the margin boxes of any atomic inlines it contains.
ISSUE: Should the hanging punctuation be included in the box instead
(so that the box is drawn around the punctuation when it is made visible through borders/background),
but rather only excluded when positioning the box
(so that the initial letter remains flush,
with the hanging punctuation properly hanging)?
See <a href="https://github.com/w3c/csswg-drafts/issues/310">discussion</a>.
<li>
In the <a>inline axis</a>,
the initial letter's margin box is placed at the start edge of the line.
If it is a non-atomic inline
with an <a lt="automatic size">automatic</a> <a>inline size</a>
and has no padding or borders,
it is negatively offset
by the distance from the start edge of its content box
to the point in the content that would have been placed
at the start edge of the containing block
if it had ''initial-letters: none''.
In the <a>block axis</a>,
the initial letter is anchored to the dominant baseline
of the <a>first formatted line</a>,
positioned with respect to that baseline
such that it would sink the number of lines
specified by 'initial-letters'’s second argument
if its containing block held only
the <a>initial letter</a> itself
followed by an infinite sequence of plain text
as the direct contents of its <a>root inline box</a>.
<figure>
<img src="images/infinite-text.png" width="300"
alt="text underlay shows how initial letter alignment is not affected
by the content of the spanned lines">
</figure>
<li>
Exclude content within the inline letter's margin box
according to 'initial-letters-wrap'.
</ol>
<h4 id="initial-letter-box">
Content-box Size, Margins, Borders, and Padding</h4>
Initial letters can be styled with margins, padding, and borders
just like any other box.
Unless 'initial-letters-align' is ''initial-letters-align/border-box'',
its vertical alignment and sizing are not affected;
however the effective exclusion area is
(and corresponds to the margin area).
When padding and borders are zero,
the initial letter may be kerned;
see below.
<h3 id="aligning-initial-letter">
Alignment of Initial Letters: the 'initial-letters-align' property</h3>
As mentioned earlier, the alignment of initial letters
depends on the script used.
The 'initial-letters-align' property can be used to specify the proper alignment.
<pre class="propdef" id="initial-letters-align">
Name: <dfn id="propdef-initial-letters-align">initial-letters-align</dfn>
Value: border-box? [ alphabetic | ideographic | hebrew | hanging ] | border-box
Initial: alphabetic
Applies to: certain inline-level boxes and <css>::first-letter</css> and inside <css>::marker</css> boxes (<a href="#first-most-inline-level">see prose</a>)
Inherited: yes
Percentages: N/A
Computed value: specified value
</pre>
This property specifies the alignment points
used to size and position an <a>initial letter</a>.
Two sets of alignment points are necessary:
the <a>over</a> and <a>under</a> alignment points of the <a>initial letter</a>
are matched to corresponding <a>over</a> and <a>under</a> points of the surrounding text.
Values have the following meanings:
<dl dfn-type="value" dfn-for="initial-letters-align">
<dt><dfn>alphabetic</dfn>
<dd>
Use the alphabetic and cap-height baselines of the surrounding text
to align the <a>initial letter</a>.
<dt><dfn>ideographic</dfn>
<dd>
Use the ideographic character face bottom and top edge baselines of the surrounding text
to align the <a>initial letter</a>.
<dt><dfn>hebrew</dfn>
<dd>
Use the alphabetic and (as yet theoretical) hebrew hanging baseline of the surrounding text
to align the <a>initial letter</a>.
<dt><dfn>hanging</dfn>
<dd>
Use the alphabetic and hanging baselines of the surrounding text
to align the <a>initial letter</a>.
<dt><dfn>border-box</dfn>
<dd>
Use the <a>initial letter box</a>’s <a>line-over</a> and <a>line-under</a> border edges
as the <a>over</a> and <a>under</a> alignment points, respectively.
</dl>
Issue: Is there a proper typographic term for the hebrew “hanging” baseline?
<div class="example">
The vertical writing mode example from <a href="#f2">Figure 2</a> could be coded as:
<pre>
span.initial {
initial-letters: 2;
initial-letters-align: ideographic;
}
</pre>
</div>
<div class="example">
Initial letter in Hebrew
<pre>
span.initial {
initial-letters: 2;
initial-letters-align: hebrew;
}
</pre>
<img src="images/hebrew-initial-letter.png" width="480"
alt="optical kerning in the presence or absence of a space after the initial letter">
</div>
Except when ''border-box'' is specified,
the alignment points of the <a>initial letter</a>
are automatically determined from its contents:
<ol>
<li>If the <a>initial letter</a>
is an atomic inline,
use its <a>over</a> and <a>under</a> content-box edges.
<li>Else if the <a>initial letter</a>
contains any character from the Han, Hangul, Kana, or Yi <a>Unicode scripts</a>,
use the ideographic character face bottom and top edge baselines.
<li>Else if the <a>initial letter</a>
contains any character from the Devanagari, Bengali, and Gurmukhi <a>Unicode scripts</a>,
use the hanging and alphabetic baselines.
<li>Else if the <a>initial letter</a>
contains any character from the Hebrew <a>Unicode scripts</a>,
use the ideographic character face bottom and top edge baselines.
<li>Else use the alphabetic and cap-height baselines.
</ol>
Issue: What is the proper alignment for South Asian scripts
that do not have the explicit hanging baseline, such as Tamil or Telugu?
See GitHub issue <a href="https://github.com/w3c/csswg-drafts/issues/864">864</a>
Note: The ordering of keywords in this property is fixed in case ''border-box''
is expanded to ''[ border-box | alphabetic | ideographic | hebrew | hanging ]''
to allow explicitly specifying the <a>initial letter</a>’s alignment points.
<h4 id="initial-letter-align-defaults">
UA Default Stylesheet for 'initial-letters-align'</h4>
In order to provide the better behavior by default,
UAs must include in their default UA style sheet the following rules:
<pre>
[lang]:lang(zh, ja, ko, ii) {
initial-letters-align: ideographic;
}
[lang]:lang(iw, yi, lad, jrb) {
initial-letters-align: hebrew;
}
[lang]:lang(hi, mr, ne, pi, kok, brx, mai, sd, sa) {
initial-letters-align: hanging;
}
/* Script tags override language tags */
[lang]:lang('*-Latn', '*-Cyrl') {
initial-letters-align: alphabetic;
}
[lang]:lang('*-Hani', '*-Hant', '*-Hans') {
initial-letters-align: ideographic;
}
</pre>
Issue: This only covers the most common cross-linguistic transcription systems.
Should we include any other / all script tags in the UA style sheet?
<h3 id="sizing-initial-letters">
Sizing Initial Letters</h3>
The size of a drop initial is determined
by the need to satisfy the required alignment.
For an <var>N</var>-line drop initial in a Western script,
the cap-height of the letter needs to be (<var>N</var> – 1) times the line-height,
plus the cap-height of the surrounding text.
Note this height is <em>not</em> the font size of the drop initial.
Actually calculating this font size is tricky.
For an <var>N</var>-line drop initial,
we find the drop initial font size to be:
<figure>
<img src="images/InitialCapEquation.png" width="604"
alt="Font size of drop cap = ((N-1) * line-height + [cap-height of para] * [font size of paragraph])/[cap-height ratio of drop initial font]">
</figure>
<!--
<div>
<math display="block"><mrow><mi>Font size of drop initial</mi><mo>=</mo></mrow><mfrac><mrow><mo>(</mo><mi>N</mi><mo>-</mo><mn>1</mn><mo>)</mo><mo>&#x00D7;</mo><mi>line-height</mi><mo>+</mo><mo>(</mo><mi>cap-height ratio of para font</mi><mo>&#x00D7;</mo><mi>font size of para</mi><mo>)</mo></mrow><mrow><mi>cap-height ratio of drop initial font</mi></mrow></mfrac></math>
</div>
-->
<div class="example">
A three-line drop initial in Adobe Minion Pro
would have a font size of 61.2pt given
12pt text, 16pt line-height, and a cap-height of 651/1000 (from the font’s OS/2 table).
</div>
The line height used in this calculation
is the 'line-height' of the containing block
(or, in the case where a baseline grid is in use,
the baseline-to-baseline spacing required by the baseline grid [[CSS3-LINE-GRID]]).
The contents of the lines spanned,
and therefore any variation in their heights and positions,
is not accounted for.
<h4 id="initial-letter-shaping">
Shaping and Glyph Selection</h4>
When 'initial-letters' is not ''normal'',
shaping <em>should</em> still occur across the box's boundaries,
see [[css-text-3#boundary-shaping]].
For example, if the first letter of the Farsi word “پس”
were styled with ''initial-letters: 2 1'',
both letters would be styled in their joined forms,
with initial-form “ﭘ” as the <a>initial letter</a>,
followed by the normally-styled final-form “ﺲ”.
Note that the two letters might not always graphically connect,
even when shaped in their joining forms.
Issue: Are there other things we need to consider here?
<h3 id="initial-letter-exclusions">
Space Around Initial Letters</h3>
The glyph(s) of an initial letter do not always fit within the specified sink.
For example, if an initial letter has a descender,
it could crash into the (n+1)th line of text.
This is not desirable.
<figure>
<img src="images/Dropcap-J-3line-crash.png" width="480"
alt="3-line drop cap with J, with descender crashing into fourth line of text">
<figcaption>Incorrect: three-line initial letter with descender.
In this font, the capital “J” extends well below the baseline (shown in red).</figcaption>
</figure>
Text is therefore excluded around the glyph bounding boxes of the initial letters.
Specifically, for non-atomic initial letters,
the content box of the element is sized to fit:
<ul>
<li>The specified amount of sink
(i.e the distance from the top alignment point to the bottom alignment point).
<li>The actual ascent and descent and side bearings of all the glyphs it contains
that are part of its inline formatting context,
even if they leak outside their em boxes.
<li>The margin boxes of all the atomic inlines it contains
that are part of its inline formatting context,
even if they leak outside its own line-height.
</ul>
The margin box of the initial letter is then made an exclusion area for subsequent text.
<figure>
<img src="images/Dropcap-J-3line-exclude.png" width="480"
alt="3-line drop cap with J, but four-line exclusion">
<figcaption>Correct: text excluded around glyph bounding box</figcaption>
</figure>
<h3 id="initial-letter-position">
Positioning and Kerning Initial Letters</h3>
In the <a>block axis</a>, the <a>initial letter</a> is positioned
to satisfy its alignment requirements. (See 'initial-letters-align'.)
In the <a>inline axis</a>, the position of the inline letter
is given by aligning its start margin edge to the start edge of the containing block.