-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
2445 lines (2023 loc) · 89.9 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<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: ED
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/2016/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 [[CSS-TEXT-3]]. 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-box; type:dfn; text:content area
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.
ISSUE: Many aspects of layout here depend on font metrics.
While the relevant metrics exist in OpenType for Latin/Cyrillic/Greek and for CJK,
they are missing for many other writing systems.
For example, the visual top metric for Hebrew has no metric in the OpenType tables.
For this module to work well for the world,
we need fonts to provide the relevant metrics for all writing systems,
and that means both that OpenType needs to allow such metrics
and font designers need to provide accurate numbers.
<h3 id="values">
Value Definitions</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> keywords as their property value.
For readability they have not been repeated explicitly.
<h2 id="model">
Inline Layout Box Model</h2>
A [=block container=] element that directly contains
[=inline-level=] content--
such as [=inline boxes=], [=atomic inlines=], and [=text runs=]--
establishes an [=inline formatting context=].
The [=block container=] also generates
a <dfn export>root inline box</dfn>,
which is an <a lt="anonymous box">anonymous</a> [=inline box=] that holds
all of its [=inline-level=] contents.
The [=root inline box=] inherits from its parent [=block container=],
but is otherwise unstyleable.
In an [=inline formatting context=],
content is laid out along the [=inline axis=],
ordered according to the
<a href="https://www.w3.org/TR/css-writing-modes-3/#text-direction">Unicode bidirectional algorithm and its controls</a> [[CSS-WRITING-MODES-3]]
and distributed according to the typesetting controls in [[CSS-TEXT-3]].
[=Inline-axis=] [=margins=], [=borders=], and [=padding=]
are respected between [=inline-level boxes=]
(and their margins do not <a href="https://www.w3.org/TR/CSS2/box.html#collapsing-margins">collapse</a>).
The rectangular area that contains the boxes
that form a line of [=inline-level content=]
is called a <dfn>line box</dfn>.
Note: <a>Line boxes</a> and <a>inline boxes</a> and <a>inline-level boxes</a>
are each different things!
See [[CSS-DISPLAY-3]] for an in-depth discussion of box types and related terminology.
[=Line boxes=] are created as needed
to hold inline-level content
within an inline formatting context.
When an [=inline box=] exceeds the [=logical width=] of a [=line box=],
or contains a <a spec="css-text-3">forced line break</a>,
it is split (see [[css-text-3#line-breaking]])
into several [=fragments=] [[css-break-3]],
which are distributed across multiple line boxes.
Like [=column boxes=] in [=multi-column layout=] [[CSS-MULTICOL-1]],
[=line boxes=] are [=fragmentation containers=]
generated by their [=formatting context=],
and are not part of the CSS [=box tree=].
Note: Inline boxes can also be <a href="https://www.w3.org/TR/css-writing-modes-3/#bidi-box-model">split into several fragments
within the same line box due to bidirectional text processing</a>.
See [[CSS-WRITING-MODES-3]].
Line boxes are stacked
as the direct contents of the [=block container box=]
in the [=block flow direction=]
and aligned within this container as specified by 'align-content' [[css-align-3]].
Thus, an [=inline formatting context=] consists of
a stack of line boxes.
Line boxes are stacked with no separation
(except as specified elsewhere,
e.g. for [=float=] <a href="https://www.w3.org/TR/CSS2/visuren.html#clearance">clearance</a>)
and they never overlap.
In general,
the [=line-left=] edge of a line box touches
the [=line-left=] edge of its [=containing block=]
and the [=line-right=] edge touches
the [=line-right=] edge of its [=containing block=],
and thus the [=logical width=] of a line box is equal to
the <a lt="inner size">inner</a> [=logical width=]
of its containing block
(i.e. the [=block container=]’s [=content box=]).
However, floating boxes or [=initial letter boxes=]
can come between the containing block edge and the line box edge,
reducing space available to, and thus the [=logical width=],
of any such impacted line boxes.
(See [[CSS2/visuren#inline-formatting]]/[[CSS2/visuren#floats]]
and [[#initial-letter-styling]].)
Within the line box,
inline-level boxes can be aligned
along the [=block axis=]
in different ways:
their over or under edges can be aligned,
or the baselines of text within them can be aligned.
See 'vertical-align' and its longhands.
The [=logical height=] of a line box is fitted to its contents
by the rules given in [[#line-sizing-property]].
Line boxes that contain no text,
no [=preserved white space=],
no [=inline boxes=] with non-zero [=margins=], [=padding=], or [=borders=],
and no other [=in-flow=] content
(such as [=atomic inlines=] or [=ruby annotations=]),
and do not end with a preserved newline
must be treated as zero-<a lt="logical height">height</a> line boxes
for the purposes of determining the positions of any elements inside of them
(such as [=absolutely positioned boxes=]),
and must be treated as not existing for any other purpose
(such as <a href="https://www.w3.org/TR/CSS2/box.html#collapsing-margins">collapsing margins</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: auto
Applies to: block containers, inline boxes, table rows, table columns, grid containers, and flex containers
Inherited: yes
Percentages: N/A
Computed value: specified keyword
Animation type: discrete
</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'', or ''sideways-right''.
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 under-side baseline to that of its parent.
This corresponds to the <code>ideo</code> baseline in OpenType.
<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 [[CSS-WRITING-MODES-3]] 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 shorthand">
Name: vertical-align
Value: <<'baseline-source'>> || <<'baseline-shift'>> || <<'alignment-baseline'>>
Initial: baseline
Applies to: inline-level boxes
Inherited: no
Percentages: N/A
</pre>
<p>This <a>shorthand</a> 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
(unless it is specifically needed to cascade its longhands independently).
<h4 id="baseline-source">
Alignment Baseline Source: the 'baseline-source' longhand</h4>
<pre class="propdef">
Name: baseline-source
Value: auto | first | last
Initial: auto
Applies to: inline-level boxes
Inherited: no
Percentages: N/A
Computed value: specified keyword
Animation type: discrete
</pre>
ISSUE: This is a rough draft, not ready for implementation. Also might rename stuff.
When an inline-level box
has more than one possible source for baseline information
(such as for a multi-line inline block or inline flex container)
this property specifies whether the <a>first baseline set</a> or <a>last baseline set</a>
is preferred for alignment.
Values have the following meanings:
<dl dfn-for=alignment-baseline dfn-type=value>
<dt><dfn>auto</dfn>
<dd>Specifies <a>last-baseline alignment</a> for ''inline-block'',
<a>first-baseline alignment</a> for everything else.
<dt><dfn>first</dfn>
<dd>Specifies <a>first-baseline alignment</a>.
<dt><dfn>last</dfn>
<dd>Specifies <a>last-baseline alignment</a>.
</dl>
<h4 id="alignment-baseline-property">
Alignment Baseline Type: the '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: specified keyword
Animation type: discrete
</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 purposes of transverse alignment within a line box,
an [=atomic inline=] that has no [=baseline sets=]
uses baselines [=synthesize baseline|synthesized=]
from its [=margin box=].
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: the '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: the specified keyword and/or a computed <<length-percentage>> value
</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 ''alignment-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 the ''baseline-shift/baseline'' value, and are looking for feedback from SVG user agents as to whether it's necessary.
<h3 id="line-height-property">
Line Spacing: the 'line-height' property</h3>
As described in the section on <a href="https://www.w3.org/TR/CSS2/visuren.html#inline-formatting">inline formatting contexts</a> [[CSS2/visuren#inline-formatting]],
user agents flow inline-level boxes into a vertical stack of [=line boxes=].
The height of a line box is determined as follows:
<ol>
<li>
The height of each [=inline-level box=] in the line box is calculated.
For replaced elements, inline-block elements, and inline-table elements,
this is the height of their [=margin box=];
for [=inline boxes=], this is their 'line-height'.
<li>
The inline-level boxes are aligned vertically
according to their 'vertical-align' property.
In case they are aligned ''top'' or ''bottom'',
they must be aligned so as to minimize the line box height.
If such boxes are tall enough,
there are multiple solutions
and CSS 2 does not define the position of the line box's baseline
(i.e., the position of the [=strut=]).
<li>
The line box height is the distance between
the uppermost box top and the lowermost box bottom.
(This includes the [=strut=],
as explained under 'line-height' below.)
</ol>
Empty inline elements generate empty inline boxes,
but these boxes still have margins, padding, borders, and a line height,
and thus influence these calculations just like elements with content.
<h4 id="leading">Leading and half-leading</h4>
CSS assumes that every font has font metrics
that specify a characteristic height above the baseline and a depth below it.
In this section we use <var>A</var> to mean that height
(for a given font at a given size)
and <var>D</var> the depth.
We also define <var>AD</var> = <var>A</var> + <var>D</var>,
the distance from the top to the bottom.
(See the note below for <a href="#sTypoAscender">how to find <var>A</var> and <var>D</var> for TrueType and OpenType fonts.</a>)
Note that these are metrics of the font as a whole
and need not correspond to the ascender and descender of any individual glyph.
The User Agent must align the glyphs in a non-replaced inline box
to each other by their relevant baselines.
Then, for each glyph,
determine the <var>A</var> and <var>D</var>.
Note that glyphs in a single element
may come from different fonts
and thus need not all have the same <var>A</var> and <var>D</var>.
If the inline box contains no glyphs at all,
or if it contains only glyphs from fallback fonts,
it is considered to contain a [=strut=] (an invisible glyph of zero width)
with the <var>A</var> and <var>D</var> of the element's first available font.
<p id="inline-box-height">When the value of the 'line-height' property
is something other than ''line-height/normal'',
determine the leading <var>L</var> to add,
where <var>L</var> = 'line-height' - <var>AD</var> of the first available font.
Half the leading is added above <var>A</var> of the first available font,
and the other half below <var>D</var> of the first available font,
giving a total height above the baseline of
<var>A'</var> = <var>A</var> + <var>L</var>/2,
and a total depth of <var>D'</var> = <var>D</var> + <var>L</var>/2.
Glyphs from fonts other than the first available font
do not impact the height or baseline of the inline box
for 'line-height' values other than ''line-height/normal''.
Note: <var>L</var> may be negative.
Boxes of child elements do not influence this height.
When the value of the 'line-height' property is ''line-height/normal'',
the height of the inline box encloses all glyphs,
going from the highest <var>A</var> to the deepest <var>D</var>.
User Agents may use different sets of font metrics
when determining <var>A</var> and <var>D</var>
depending on whether the 'line-height' property is
''line-height/normal'' or some other value,
for instance taking external leading metrics into account
only in the ''line-height/normal'' case.
Although margins, borders, and padding of non-replaced elements
do not enter into the line box calculation,
they are still rendered around inline boxes.
This means that if the height specified by 'line-height'
is less than the content height of contained boxes,
backgrounds and colors of padding and borders may "bleed" into adjoining line boxes.
User agents should render the boxes in document order.
This will cause the borders on subsequent lines
to paint over the borders and text of previous lines.
Note: CSS 2 does not define what the content area of an inline box is
(see [[#line-fill]])
and thus different UAs may draw the backgrounds and borders in different places.
<p class=note id=sTypoAscender>Note: It is recommended that
implementations that use OpenType or TrueType fonts
use the metrics <code>sTypoAscender</code> and <code>sTypoDescender</code>
from the font's OS/2 table
for <var>A</var> and <var>D</var>
(after scaling to the current element's font size).
In the absence of these metrics,
the "Ascent" and "Descent" metrics from the HHEA table should be used.
<pre class="propdef">
Name: line-height
Value: normal | <<number>> | <<length-percentage>>
Initial: normal
Applies to: inline boxes
Inherited: yes
Percentages: computed relative to ''1em''
Computed value: the specified keyword, a number, or a computed <<length>> value
</pre>
On a [=block container=] whose content is composed of [=inline-level boxes=],
'line-height' specifies the <em>minimal</em> height of line boxes within the element.
The minimum height consists of
a minimum height above the baseline
and a minimum depth below it,
exactly as if each line box starts with a zero-width inline box
with the element's font and line height properties.
We call that imaginary box a <dfn>strut</dfn>.
(The name is inspired by TeX.).
The height and depth of the font
above and below the baseline
are assumed to be metrics that are contained in the font.
On a non-replaced [=inline box=],
'line-height' specifies the height that is used
in the calculation of the [=line box=] height.
Values for this property have the following meanings:
<dl dfn-for=line-height dfn-type=value>
<dt><dfn>normal</dfn>
<dd>
Tells user agents to determine the height of the inline box automatically
based on font metrics.
See above for details.
<dt><dfn><<length>></dfn>
<dd>
The specified length is used in the calculation of the line box height.
Negative values are illegal.
<dt><dfn><<number>></dfn>
<dd>
The used value of the property is this number
multiplied by the element's font size.
Negative values are illegal.
The [=computed value=] is the same as the [=specified value=].
<dt><dfn><<percentage>></dfn>
<dd>
The [=computed value=] of the property
is this percentage multiplied by the element's computed 'font-size'.
Negative values are illegal.
</dl>
<div class="example">
The three rules in the example below have the same resultant line height:
<pre><code highlight=css>
div { line-height: 1.2; font-size: 10pt } /* number */
div { line-height: 1.2em; font-size: 10pt } /* length */
div { line-height: 120%; font-size: 10pt } /* percentage */
</code></pre>
</div>
Note: When there is only one value of 'line-height'
(other than ''line-height/normal'')
for all inline boxes in a block container box
and they all use the same first available font
(and there are no replaced elements, inline-block elements, etc.),
the above will ensure that baselines of successive lines
are exactly 'line-height' apart.
This is important when columns of text in different fonts have to be aligned,
for example in a table.
ISSUE: The fact that percentages compute to lengths is annoying.
See also href="https://github.com/w3c/csswg-drafts/issues/3118">Issue 3118</a>
and <a href="https://github.com/w3c/csswg-drafts/issues/2165">Issue 2165</a>.
<h3 id="line-sizing-property">
Line Sizing Containment: the 'line-sizing' property</h3>
<pre class="propdef">
Name: line-sizing
Value: legacy | normal
Initial: legacy
Applies to: inline boxes
Inherited: yes
Percentages: N/A
Computed value: the specified keyword
</pre>
ISSUE: This is a rough draft of a proposal, and has not yet been approved by the CSSWG.
See discussion in <a href="https://github.com/w3c/csswg-drafts/issues/3199">Issue 3199</a>, <a href="https://lists.w3.org/Archives/Public/www-style/2011Mar/0364.html">Hyatt's message</a>, and <a href="https://dev.w3.org/cvsweb/~checkout~/csswg/css3-linebox/Attic/Overview.html?rev=1.5;content-type=text%2Fhtml#LineStacking">dbaron's proposal</a>.
This property controls the method by which line boxes are sized,
and thus the spacing between lines of text.
Values have the following meanings:
<dl dfn-for=line-sizing dfn-type=value>
<dt><dfn>legacy</dfn>
<dd>
The inline box contributes to the sizing of its line box
based on its 'line-height',
rather than based on its box edges,
as defined in [[!CSS2]].
In Quirks Mode [[!QUIRKS]],
any <a>inline box</a> <a lt="box fragment">fragment</a>
that has zero borders and padding and
that does not directly contain text or <a>preserved white space</a> [[!CSS-TEXT-3]]
is ignored when sizing the line box.
Note: In this model, vertical rhythm is broken
any time there is a change in font metrics within a paragraph.
<dt><dfn>normal</dfn>
<dd>
The inline box contributes to the sizing of its line box
based on its <a>margin box</a>,
rather than its 'line-height'.
Half-leading is inserted inside the <a>content box</a> edges,
rather than overlapping the padding/border/margin areas.
However, positive half-leading is only applied to the <a>root inline box</a>.
Negative half-leading is applied to all inline boxes,-
reducing the size of the <a>content box</a> as needed.
Note: This will give consistent line spacing
as long as there is some amount of leading added,
such that the half-leading on the root inline
is large enough to accommodate the unleaded ascent/descent of its descendants.
The line box will grow, however, to accommodate
content that would otherwise overflow,
to avoid overlap between lines.
</dl>
ISSUE: Should this property apply to block containers or to inline boxes?
In the latter case, an individual inline could say "pay attention to me"
or "don't pay attention to me".
<h3 id="leading-trim-property">
Leading Control: the 'leading-trim-over' and 'leading-trim-under' properties and 'leading-trim' shorthand</h3>
ISSUE: This is a rough draft of a proposal,
and is likely to change significantly
as design critiques and use cases are registered.
Values and property names may be added, dropped, and/or renamed,
and the overall syntax or behavior may change.
Do not implement (yet).
The CSSWG particularly invites feedback on
which font metrics need corresponding keyword values.
To ensure consistent spacing in the basic case of running text,
CSS line layout introduces leading both above and below
the text content of each line.
In addition, the ascend and descent font metrics themselves
include extra space above and below the most common glyph sizes
in order to accommodate occasional characters and diacritics
which ascend or descend beyond the typical bounds.
This prevents subsequent lines of text from overlapping each other.
However, all this extra spacing interferes with visual alignment
and with control over effective (visually-apparent) spacing.
The 'leading-trim' properties allow controlling the spacing above and below
the first and last lines of a block.
It allows precise control over spacing;
moreover, by relying on font metrics rather than hard-coded lengths,
it allows content to be resized, rewrapped, and rendered in a variety of fonts
while maintaining that spacing.
<div class="example">
<!-- Example from Weston Thayer in https://github.com/w3c/csswg-drafts/issues/3240#issuecomment-432375650 -->
A common problem is vertical centering.
It's easy to vertically center the text container to an icon,
but because the visual boundaries of Latin text
are the cap height and the alphabetic baseline,
rather than the ascent and descent,
this often doesn't yield the intended visual effect.
<figure>
<img src="images/leading-trim-centering-fail.png"
alt="Consider some Latin text placed to the right of an image,
to be centered between its top and bottom.
Measuring from the top of the image to the top of the text box yields 13px;
likewise measuring from the bottom of the image to the bottom of the text box yields 13px,
theoretically perfectly centering the text.
However, measuring from the top of the image to the cap-height yields 21px;
and measuring from the bottom to the alphabetic baseline yields 19px,
showing that visually the text is not actually centered.">
<figcaption>
Measuring to the top/bottom of the text may yield equal results,
but measuring to the visual bounds shows that it is not visually centered.
</figcaption>
</figure>
To center the text visually,
it's necessary to assume the cap height and alphabetic baseline
as the top and bottom edges of the text,
respectively.
<figure>
<img src="images/leading-trim-centering-goal.png"
alt="If the text were visually centered,
the distance between the top of the image and the cap height would be 20px,
and the distance between the bottom of the image and the alphabetic baseline would be equally 20px."
style="width: 50%">
<figcaption>
Measuring to the cap height / alphabetic baseline
instead of the ascent / descent
and equalizing those distances
visually centers the text.
</figure>
By using 'leading-trim' to strip out the spacing above the cap height
and below the alphabetic baseline,
centering the box actually centers the text;
and does so reliably, regardless of what font is used to render it.
<figure>
<img src="images/leading-trim-centering-variants.gif"
alt="">
<figcaption>
Even though different fonts have different cap heights,
by using the font's metric rather than a magic number,
the layout intention is met even as the font is changed.
</figcaption>
</figure>
</div>
<pre class="propdef">
Name: leading-trim-over
Value: normal | text | cap | ex | ideographic | ideographic-ink
Initial: normal
Applies to: block containers
Inherited: no
Percentages: N/A
Computed value: the specified keyword
</pre>
The 'leading-trim-over' property trims
the <a>line-over</a> side of the first line box in the block container
to better match the box’s content edge to its text content.
The property affects only the <a>first formatted line</a> of the block container;
if there is no such line, it has no effect.
Values have the following meanings:
<dl dfn-for="leading-trim-over, leading-trim" dfn-type=value>
<dt><dfn>normal</dfn>
<dd>
Half-leading is applied over the first line,
just as for every other line.
<dt><dfn>text</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the text-top metric
of the root inline box.
<dt><dfn>cap</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the cap-height metric
of the root inline box.
<dt><dfn>ex</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the ex-height metric
of the root inline box.
<dt><dfn>ideographic</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the ideographic top (<code>idtp</code>) metric
of the root inline box.
<dt><dfn>ideographic-ink</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the ideographic character face top (<code>icft</code>) metric
of the root inline box.
</dl>
<pre class="propdef">
Name: leading-trim-under
Value: normal | text | alphabetic | ideographic | ideographic-ink
Initial: normal
Applies to: block containers
Inherited: yes
Percentages: N/A
Computed value: the specified keyword
</pre>
The 'leading-trim-over' property trims
the <a>line-over</a> side of the first line box in the block container
to better match the box’s content edge to its text content.
The property affects only the <a>first formatted line</a> of the block container;
if there is no such line, it has no effect.
Values have the following meanings:
<dl dfn-for="leading-trim-under" dfn-type=value>
<dt><dfn>normal</dfn>
<dd>
Half-leading is applied over the first line,
just as for every other line.
<dt><dfn>text</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the text-top metric
of the root inline box.
<dt><dfn>alphabetic</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the alphabetic baseline metric
of the root inline box.
<dt><dfn>ideographic</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the ideographic bottom (<code>ideo</code>) metric
of the root inline box.
<dt><dfn>ideographic-ink</dfn>
<dd>
Half-leading is not applied over the first line;
the top of the line box is set to
the ideographic character face top (<code>icfb</code>) metric
of the root inline box.
</dl>
<pre class="propdef">
Name: leading-trim
Value: normal | text | cap | ex | ideographic | ideographic-ink
Initial: normal
Applies to: block containers
Inherited: no
Percentages: N/A
Computed value: the specified keyword
</pre>
This property is a <a>shorthand</a> of 'leading-trim-over' and 'leading-trim-under'.
If ''leading-trim/cap'' or ''leading-trim/ex'' is specified,
'leading-trim-over' is set to that value
and 'leading-trim-under' is set to ''leading-trim-under/alphabetic'';
otherwise both <a>longhands</a> are set to the specified keyword.
<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: specified keyword
Animation type: discrete
</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§10.6.1</a>.
<dt><dfn>stretch</dfn>
<dd>
Once the line box has been sized,
the final <a>logical height</a> of the <a>inline box</a>’s <a>content area</a>
is calculated as the <a>stretch fit</a>
into the line box,
and it is 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.
The 'height' property does not apply.
The height of the content area should be based on the font,
but this specification does not specify how.
A UA may, e.g., use the the maximum ascender and descender of the font.
(This would ensure that glyphs with parts above or below the em-box
still fall within the content area,
but leads to differently sized boxes for different fonts.)
The vertical padding, border and margin of an inline, non-replaced box
start at the top and bottom of the content area,
and has nothing to do with the 'line-height'.
But only the 'line-height' is used when calculating
the height of the line box.
If more than one font is used
(this could happen when glyphs are found in different fonts),
the height of the content area is not affected
by the glyphs from the fallback fonts,
and only depends on the first available font.
<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.