-
Notifications
You must be signed in to change notification settings - Fork 669
/
Overview.bs
1989 lines (1719 loc) · 77.8 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
<pre class='metadata'>
Title: CSS Pseudo-Elements Module Level 4
Shortname: css-pseudo
Level: 4
Status: ED
Work Status: Refining
Group: csswg
ED: https://drafts.csswg.org/css-pseudo-4/
TR: https://www.w3.org/TR/css-pseudo-4/
Previous Version: https://www.w3.org/TR/2020/WD-css-pseudo-4-20201231/
Previous Version: https://www.w3.org/TR/2019/WD-css-pseudo-4-20190225/
Previous Version: https://www.w3.org/TR/2016/WD-css-pseudo-4-20160607/
Previous Version: https://www.w3.org/TR/2015/WD-css-pseudo-4-20150115/
!Issues List: <a href="https://drafts.csswg.org/css-pseudo/#issues-index">Tracked in Editor's Draft</a>
Editor: Daniel Glazman, Disruptive Innovations, w3cid 13329
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Alan Stearns, Adobe Systems Inc., [email protected], w3cid 46659
Abstract: This CSS module defines pseudo-elements, abstract elements that represent portions of the CSS render tree that can be selected and styled.
At Risk: the ''::prefix'' and ''::postfix'' sub-elements of ''::first-letter''
Ignored Terms: initial-letter, PseudoElement, pseudo(), selectors
Default Highlight: css
Indent: 2
WPT Path Prefix: css/css-pseudo/
WPT Display: closed
</pre>
<pre class="link-defaults">
spec:css-color-4; type:value; text:currentcolor
spec:css-color-4; type:property; text:color
spec:fill-stroke-3; type:property; text:stroke-width
spec:css-lists-3; type:dfn; text:marker
spec:css-backgrounds-3; type:property; text:box-shadow
</pre>
<h2 id="intro">Introduction</h2>
<em>This section is informative.</em>
<a>Pseudo-elements</a> represent abstract elements of the document
beyond those elements explicitly created by the document language.
Since they are not restricted to fitting into the document tree,
they can be used to select and style portions of the document
that do not necessarily map to the document's tree structure.
For instance, the ''::first-line'' pseudo-element can
select content on the first formatted line of an element
<em>after</em> text wrapping,
allowing just that line to be styled differently
from the rest of the paragraph.
Each pseudo-element is associated with an <a>originating element</a>
and has syntax of the form ''::name-of-pseudo''.
This module defines the pseudo-elements that exist in CSS
and how they can be styled.
For more information on pseudo-elements in general,
and on their syntax and interaction with other <a>selectors</a>,
see [[!SELECTORS-4]].
<h2 id="typographic-pseudos">
Typographic Pseudo-elements</h2>
<h3 id="first-line-pseudo">
First-Line Text: the ''::first-line'' pseudo-element</h3>
The <dfn>::first-line</dfn> [=pseudo-element=] represents
the contents of the [=first formatted line=]
of its [=originating element=].
<wpt>
first-line-allowed-properties.html
first-line-and-marker.html
first-line-and-placeholder.html
first-line-change-inline-color-nested.html
first-line-change-inline-color.html
first-line-first-letter-insert-crash.html
first-line-float-mapped-attribute-crash.html
first-line-inherited-no-transition.html
first-line-inherited-transition-crash.html
first-line-inherited-with-transition.html
first-line-input-image-crash.html
first-line-line-height-001.html
first-line-line-height-002.html
first-line-nested-gcs.html
first-line-on-ancestor-block.html
first-line-opacity-001-ref.html
first-line-opacity-001.html
first-line-replaced-001.html
first-line-with-before-after.html
first-line-with-inline-block-before.html
first-line-with-inline-block.html
first-line-with-out-of-flow-and-nested-div.html
first-line-with-out-of-flow-and-nested-span.html
first-line-with-out-of-flow.html
</wpt>
<div class="example">
The rule below means
“change the letters of the first line of every <code>p</code> element to uppercase”:
<pre class="lang-css">p::first-line { text-transform: uppercase }</pre>
The selector ''p::first-line''
does not match any real document element.
It instead matches a pseudo-element
that the user agent will automatically insert
at the beginning of every <code>p</code> element.
</div>
Note: Note that the length of the first line depends on a number of factors,
including the width of the page, the font size, etc.
<div class="example" id="first-line-example">
For example, given an ordinary HTML [[HTML5]] paragraph such as:
<pre class="lang-markup">
<P>This is a somewhat long HTML paragraph
that will be broken into several lines.
The first line will be styled
by the ‘::first-line’ pseudo-element.
The other lines will be treated
as ordinary lines in the paragraph.</P>
</pre>
Depending on the width of the element,
its lines might be broken as follows:
<pre class="figure">
THIS IS A SOMEWHAT LONG HTML PARAGRAPH THAT
will be broken into several lines. The first
line will be styled by the ‘::first-line’
pseudo-element. The other lines will be
treated as ordinary lines in the paragraph.
</pre>
or alternately as follows:
<pre class="figure">
THIS IS A SOMEWHAT LONG
HTML paragraph that will
be broken into several
lines. The first line will
be styled by the
‘::first-line’ pseudo-
element. The other lines
will be treated as ordinary
lines in the paragraph.
</pre>
</div>
<h4 id="first-text-line">
Finding the First Formatted Line</h4>
In CSS, the ''::first-line'' pseudo-element
can only have an effect when attached to a <a>block container</a>:
* The <dfn export>first formatted line</dfn> of
a [=block container=] that establishes an [=inline formatting context=]
represents the [=inline-level=] content of its first [=line box=].
* The [=first formatted line=] of
a [=block container=] or [=multi-column container=]
that contains [=block-level=] content
(and is not a [=table wrapper box=])
is the [=first formatted line=] of
its first [=in-flow=] [=block-level=] child.
If no such line exists,
it has no [=first formatted line=].
Note: The [=first formatted line=] can be an empty line.
For example, the first line of the <code>p</code> in
<code class="lang-markup"><p><br>First…</code>
doesn't contain any letters.
Thus the word “First” is not on the first formatted line,
and will not be affected by ''p::first-line''.
Note: The first line of a [=block container=]
that does not itself participate in a [=block formatting context=]
cannot be the first formatted line of an ancestor element.
Thus, in <code class="lang-markup"><DIV><P STYLE="display: inline-block">Hello<BR>Goodbye</P> etcetera</DIV></code>
the first formatted line of the <code>DIV</code> is not the line “Hello”,
but rather the line that contains that entire inline block.
When a [=first formatted line=] is represented
by multiple ''::first-line'' pseudo-elements,
they are nested in the same order as their [=originating elements=].
The [=inline-level=] contents of this line--
including its [=root inline box=] fragment--
are nested within the innermost ''::first-line'' [=pseudo-element=].
<div class="example">
Consider the following markup:
<pre class="lang-markup">
<DIV>
<P>First paragraph</P>
<P>Second paragraph</P>
</DIV>
</pre>
If we assume a [=fictional tag sequence=] to represent
the elements’ ''::first-line'' pseudo elements,
it would be something like:
<pre class="lang-markup">
<DIV>
<P><DIV::first-line><P::first-line>First paragraph</P::first-line></DIV::first-line></P>
<P><P::first-line>Second paragraph</P::first-line></P>
</DIV>
</pre>
</div>
<h4 id="first-line-styling">
Styling the ''::first-line'' Pseudo-element</h4>
The ''::first-line'' pseudo-element’s generated box
behaves similar to that of an [=inline-level box=], but with certain restrictions.
The following CSS properties apply to a ''::first-line'' pseudo-element:
<ul>
<li>all font properties (see [[CSS-FONTS-4]])
<li>the 'color' and 'opacity' properties (see [[CSS-COLOR-4]])
<li>all background properties (see [[CSS-BACKGROUNDS-4]])
<li>any typesetting properties that apply to inline elements (see [[CSS-TEXT-3]])
<li>all text decoration properties (see [[CSS-TEXT-DECOR-3]])
<li>the 'ruby-position' property (see [[CSS-RUBY-1]])
<li>any inline layout properties that apply to inline elements (see [[CSS-INLINE-3]])
<li>any other properties defined to apply to ''::first-line''
by their respective specifications
</ul>
User agents may apply other properties as well except for
the following excluded properties:
<ul>
<li>'writing-mode'
<li>'direction'
<li>'text-orientation'
</ul>
Note: Setting 'line-height' on ''::first-line'' inherits to
the fragment of the [=root inline box=]
that wraps the contents of the first line,
and therefore can both increase and decrease the height of the first line box.
<h4 id="first-line-inheritance">
Inheritance and the ''::first-line'' Pseudo-element</h4>
During CSS [=inheritance=],
the [=box fragment|fragment=] of a child that occurs on the first line
inherits any standard [=inherited properties=]--
except the properties excluded above--
from the ''::first-line'' pseudo-element.
For all other properties,
including all [=custom properties=] [[!CSS-VARIABLES-1]],
inheritance is
from the non-pseudo parent.
(The portion of a child element that does not occur on the first line
always inherits from the non-pseudo parent.)
<div class="example">
In the common case (of standard inherited CSS properties),
[=inheritance=] into and from a ''::first-line'' pseudo-element
can be understood by writing out a <dfn>fictional tag sequence</dfn>
to represent ''::first-line''.
Consider the <a href="#first-line-example">earlier example</a>;
in case of the first rendering, the fictional tag sequence would be:
<pre class="lang-markup">
<P><strong><p::first-line></strong>This is a somewhat long HTML paragraph
that<strong></p::first-line></strong> will be broken into several lines.
The first line will be styled
by the ‘::first-line’ pseudo-element.
The other lines will be treated
as ordinary lines in the paragraph.</p>
</pre>
And in the case of the second rendering:
<pre class="lang-markup">
<p><strong><p::first-line></strong>This is a somewhat long<strong></p::first-line></strong> HTML paragraph
that will be broken into several lines.
The first line will be styled
by the ‘::first-line’ pseudo-element.
The other lines will be treated
as ordinary lines in the paragraph.</p>
</pre>
</div>
<div class="example">
If a pseudo-element breaks up a real element,
the effect can often be described
by a <a>fictional tag sequence</a>
that closes and then re-opens the element.
Suppose we mark up the earlier example
with a <code>span</code> element encompassing the first sentence:
<pre class="lang-markup">
<p><strong><span></strong>This is a somewhat long HTML paragraph
that will be broken into several lines.<strong></span></strong>
The first line will be styled
by the ‘::first-line’ pseudo-element.
The other lines will be treated
as ordinary lines in the paragraph.</p>
</pre>
The effect of the first rendering
would be similar to the following [=fictional tag sequence=]:
<pre class="lang-markup">
<p><strong><p::first-line><span></strong>This is a somewhat long HTML paragraph
that<strong></span></p::first-line><span></strong> will be broken into several lines.<strong></span></strong>
The first line will be styled
by the ‘::first-line’ pseudo-element.
The other lines will be treated
as ordinary lines in the paragraph.</p>
</pre>
</div>
<h3 id="first-letter-pseudo">
First-Letter Text: ''::first-letter'' pseudo-element and its ''::prefix'' and ''::postfix'' children</h3>
<wpt>
first-letter-001.html
first-letter-002.html
first-letter-003.html
first-letter-004.html
first-letter-005.html
first-letter-allowed-properties.html
first-letter-and-sibling-display-change.html
first-letter-and-whitespace.html
first-letter-background-image-dynamic.html
first-letter-background-image.html
first-letter-bidi-pre-crash.html
first-letter-block-to-inline.html
first-letter-crash.html
first-letter-digraph.html
first-letter-exclude-block-child-marker.html
first-letter-exclude-inline-child-marker.html
first-letter-exclude-inline-marker.html
first-letter-hi-001.html
first-letter-hi-002.html
first-letter-list-item-dynamic-001.html
first-letter-of-html-root-refcrash.html
first-letter-opacity-001-ref.html
first-letter-opacity-001.html
first-letter-opacity-float-001.html
first-letter-punctuation-and-space.html
first-letter-punctuation-dynamic.html
first-letter-skip-empty-span-nested.html
first-letter-skip-empty-span.html
first-letter-skip-marker.html
first-letter-text-and-display-change.html
first-letter-width-2.html
first-letter-width.html
first-letter-with-before-after.html
first-letter-with-preceding-new-line.html
first-letter-with-quote.html
first-letter-with-span.html
</wpt>
<div class="figure">
<img alt="A drop-cap initial letter, including the opening quotation mark before it." src="images/first-letter2.gif">
</div>
The <dfn>::first-letter</dfn> [=pseudo-element=] represents
the first Letter, Number, or Symbol
(Unicode category <code>L*</code>, <code>N*</code>, or <code>S*</code>) [=typographic character unit=]
on the <a>first formatted line</a> of its <a>originating element</a>
(the <dfn>first letter</dfn>)
as well as its associated punctuation.
Collectively, this text is the <dfn>first-letter text</dfn>.
The ''::first-letter'' pseudo-element can be used
to create “initial caps” and “drop caps”,
which are common typographic effects.
<div class="example">
For example, the following rule creates a 2-line drop-letter
on every paragraph following a level-2 header,
using the 'initial-letter' property defined in [[CSS-INLINE-3]]:
<pre class="lang-css">h2 + p::first-letter { initial-letter: 3; }</pre>
</div>
Note: The [=first letter=] may in fact be a digit,
e.g., the “6” in “67 million dollars is a lot of money.”
To allow independent styling of the [=first letter=] itself
and its adjacent punctuation,
associated preceding punctuation
is represented by the <dfn for="::first-letter">::prefix</dfn>
[=sub-pseudo-element=] of the ''::first-letter'' [=pseudo-element=]
(''::first-letter::prefix'');
and associated following punctuation
is represented by the <dfn for="::first-letter">::postfix</dfn>
[=sub-pseudo-element=] of the ''::first-letter'' [=pseudo-element=]
(''::first-letter::postfix'').
See [[#first-letter-pattern]], below.
<h4 id="first-letter-pattern">
First Letters and Associated Punctuation</h4>
As explained in [[CSS-TEXT-3#characters]],
a <a>typographic character unit</a> can include more than one Unicode codepoint.
For example, combining characters must be kept with their base character.
Also, languages may have additional rules
about how to treat certain letter combinations.
In Dutch, for example, if the letter combination "ij" appears at the beginning of an element,
both letters should be considered within the ''::first-letter'' pseudo-element. [[UAX29]]
When selecting the [=first letter=],
the UA should tailor its definition of <a>typographic character unit</a>
to reflect the first-letter traditions of
the ''::first-letter'' pseudo-element’s <em>[=containing block=]</em>’s [=content language=].
Preceding and following punctuation
must also be included as part of the [=first-letter text=]
in the ''::first-letter'' pseudo-element
as follows:
<ul>
<li>
All punctuation--
i.e, characters that belong to the Punctuation (<code>P*</code>) <a>Unicode general category</a> [[!UAX44]]--
that precedes the [=first letter=].
<li>
Any punctuation other than opening punctuation and dashes--
i.e. characters that belong to the Punctuation (<code>P*</code>) <a>Unicode general category</a>,
excluding Open Punctuation (<code>Ps</code>)
and Dash Punctuation (<code>Pd</code>)--
that follows the [=first letter=].
<li>
Any intervening typographic space--
i.e. characters that belong to the <code>Zs</code> Unicode general category [[!UAX44]]
<em>other than</em>
U+3000 IDEOGRAPHIC SPACE or
any <a spec=css-text-3>word-separator characters</a>
</ul>
<div class="note">
Informally represented, the [=first-letter text=]’s pattern here
can be roughly
(ignoring the exclusion of word separators from <code>Zs</code>)
represented as
<code highlight="bnf" style="font-family: inherit">
(P (Zs|P)*)? (L\|N\|S) ((Zs|P−(Ps|Pd))* (P−(Ps|Pd))?</code>
or, alternatively,
<code highlight="bnf" style="font-family: inherit">
([P] [Zs P]*)? [L N S] ([Zs [P--[Ps Pd]]]* [P--[Ps Pd]])?</code>
<!-- this is not actually BNF, but it highlights better that way -->
<!-- Bikeshed is <a href="https://github.com/tabatkins/bikeshed/issues/2202">eating punctuation</a> in this note (unless escaped with undocumented escape sequences), which is not helpful. -->
<pre class=railroad>
Optional:
Sequence:
N: P
ZeroOrMore:
Choice:
N: P
N: Zs
Choice:
N: L
N: N
N: S
Optional:
Sequence:
N: P − (Ps ∪ Pd)
ZeroOrMore:
Choice:
N: P − (Ps ∪ Pd)
N: Zs
</pre>
</div>
See [[css-text-3#characters]] and [[css-text-3#character-properties]]
for more information on [=typographic character units=]
and their Unicode properties.
[[!CSS-TEXT-3]]
<h4 id="first-letter-application">
Finding the First-Letter Text</h4>
As with ''::first-line'',
the ''::first-letter'' pseudo-element
can only have an effect when attached to a [=block container=].
Its [=first-letter text=] is the first such [=inline-level content=]
participating in the [=inline formatting context=]
of its [=originating element=]’s [=first formatted line=],
if it is not preceded by any other in-flow content
(such as images or inline tables) on its line.
For this purpose, any [=marker boxes=] are ignored,
as if they were out-of-flow.
However, if an element has in-flow ''::before'' or ''::after'' content,
the [=first-letter text=] is selected from the content of the element
<em>including</em> that generated content.
<div class="example">
Example:
After the rule <code class="lang-css">p::before {content: "Note: "}</code>, the
selector ''p::first-letter'' matches the "N" of "Note".
</div>
If no qualifying text exists,
then there is no [=first-letter text=]
and no ''::first-letter'' pseudo-element.
Note: When the [=first formatted line=] is empty,
''::first-letter'' will not match anything.
For example, in this HTML fragment:
<code class="lang-markup"><p><br>First...</code>
the first line doesn't contain any letters,
so ''::first-letter'' doesn't match anything.
In particular, it does not match the “F” of “First”,
which is on the second line.
Note: As with ''::first-line'',
the [=first-letter text=] of a [=block container=]
that does not participate in a [=block formatting context=]
cannot be the [=first-letter text=] of an ancestor element.
Thus, in <code class="lang-markup"><DIV><P STYLE="display: inline-block">Hello<BR>Goodbye</P> etcetera</DIV></code>
the [=first letter=] of the <code>DIV</code> is not the letter “H”.
In fact, the <code>DIV</code> doesn't have a [=first letter=].
Any portion of the [=first-letter text=]
that is wrapped to the next line
no longer forms part of the ''::first-letter'' [=pseudo-element=].
<h4 id="first-letter-tree">
Inheritance and Box Tree Structure of the First-Letter Pseudo-elements</h4>
The ''::first-letter'' pseudo-element is wrapped
immediately around the [=first-letter text=] it represents,
even if that text is in a descendant.
When a [=first-letter text=] is represented by multiple ''::first-letter'' pseudo-elements,
they are nested in the same order as their [=originating elements=].
[=Inheritance=] behaves accordingly.
<div class="example">
Consider the following markup:
<pre class="lang-markup">
<div>
<p><span>The first few words</span>
and the rest of the paragraph.
</div>
</pre>
If we assume a [=fictional tag sequence=]
to represent the elements’ ''::first-letter'' pseudo-elements,
it would be something like:
<pre>
<div>
<p><span><strong><div::first-letter><p::first-letter></strong>T<strong></…></…></strong>he first few words</span>
and the rest of the paragraph.
</div>
</pre>
</div>
If any ''::first-letter::prefix'' or ''::first-letter::postfix'' [=pseudo-elements=] exist,
they are nested within the innermost ''::first-letter'',
and otherwise interpreted similar to ''::first-letter'' itself.
<div class="example">
Consider the following markup:
<pre class="lang-markup">
<div>
<p><span>“The first few words</span>
and the rest of the quotation.
</div>
</pre>
If we assume a [=fictional tag sequence=]
to represent the elements’ ''::first-letter'' pseudo-elements,
it would be something like:
<pre>
<div>
<p><span><div::first-letter><p::first-letter><strong><div::first-letter::prefix><p::first-letter::prefix></strong>“<strong></…></…></strong>T</…></…>he first few words</span>
and the rest of the paragraph.
</div>
</pre>
</div>
If the characters that would form the [=first-letter text=]
are not all in the same element
(as the <code>‘T</code> in <code class="lang-css"><p>‘<em>T...</code>),
the user agent may create the ''::first-letter'' pseudo-element
(and its ''::prefix'' or ''::postfix'' sub-elements, if any)
from one of the elements, or all elements,
or simply not create the pseudo-element(s).
Additionally, if the [=first-letter text=]
is not at the start of the line
(for example due to bidirectional reordering,
or due to a [=list item=] [=marker=] with ''list-style-position: inside''),
then the user agent is not required to create the pseudo-element(s).
A ''::first-letter'' pseudo-element is contained within
any ''::first-line'' pseudo-elements,
and thus inherits (potentially indirectly) from ''::first-line'',
the same as any [=inline box=] on the same line.
<h4 id="first-letter-styling">
Styling the First-Letter Pseudo-elements</h4>
In CSS a ''::first-letter'' [=pseudo-element=]
(and its ''::prefix'' and ''::postfix'' sub-elements)
is similar to an [=inline box=].
The following properties apply to
''::first-letter'', ''::first-letter::prefix'', and ''::first-letter::postfix''
pseudo-elements:
<ul>
<li>all font properties (see [[CSS-FONTS-4]])
<li>the 'color' and 'opacity' properties (see [[CSS-COLOR-4]])
<li>all background properties (see [[CSS-BACKGROUNDS-4]])
<li>any typesetting properties that apply to inline elements (see [[CSS-TEXT-4]])
<li>all text decoration properties (see [[CSS-TEXT-DECOR-4]])
<li>any inline layout properties that apply to inline elements (see [[CSS-INLINE-3]])
<li>margin and padding properties (see [[CSS22]])
<li>border properties and 'box-shadow' (see [[CSS-BACKGROUNDS-4]])
<li>any other properties defined to apply to ''::first-letter''
by their respective specifications
</ul>
User agents may apply other properties as well.
However,
in no case may the application of such unlisted properties to ''::first-letter'' change
what [=first-letter text=] is represented by that ''::first-letter''.
Note: In previous levels of CSS,
user agents were allowed to choose a line height, width, and height
based on the shape of the letter,
to approximate font sizes;
and to take the glyph outline into account when performing layout.
The possibility of such loosely-defined magic has been intentionally removed,
as it proved to be a poor solution for the intended use case (drop caps and raised caps),
yet caused interoperability problems.
See 'initial-letter' in [[CSS-INLINE-3]]
for explicitly handling drop caps and raised caps.
<h2 id="highlight-pseudos">
Highlight Pseudo-elements</h2>
<h3 id="highlight-selectors">
Selecting Highlighted Content: the ''::selection'', ''::target-text'', ''::spelling-error'', and ''::grammar-error'' pseudo-elements</h3>
<wpt>
grammar-spelling-errors-001.html
grammar-spelling-errors-002.html
highlight-cascade/cascade-highlight-001.html
highlight-cascade/cascade-highlight-002.html
highlight-cascade/cascade-highlight-004.html
highlight-cascade/cascade-highlight-005.html
highlight-cascade/highlight-cascade-001.html
highlight-cascade/highlight-cascade-003.html
highlight-cascade/highlight-cascade-004.html
highlight-cascade/highlight-cascade-005.html
highlight-cascade/highlight-cascade-006.xhtml
highlight-cascade/highlight-cascade-007.html
highlight-cascade/highlight-cascade-008.html
highlight-cascade/highlight-cascade-009.html
highlight-cascade/highlight-currentcolor-computed-inheritance.html
highlight-cascade/highlight-currentcolor-computed-visited.html
highlight-cascade/highlight-currentcolor-computed.html
highlight-cascade/highlight-currentcolor-painting-properties-001.html
highlight-cascade/highlight-currentcolor-painting-properties-002.html
highlight-cascade/highlight-currentcolor-painting-text-shadow-001.html
highlight-cascade/highlight-currentcolor-painting-text-shadow-002.html
highlight-cascade/highlight-currentcolor-root-explicit-default-001.html
highlight-cascade/highlight-currentcolor-root-explicit-default-002.html
highlight-cascade/highlight-currentcolor-root-implicit-default-001.html
highlight-cascade/highlight-currentcolor-root-implicit-default-002.html
highlight-cascade/highlight-pseudos-computed.html
highlight-cascade/highlight-pseudos-inheritance-computed-001.html
highlight-cascade/highlight-pseudos-visited-computed-001.html
highlight-custom-properties-dynamic-001.html
highlight-painting-005-crash.html
highlight-painting-currentcolor-001.html
highlight-painting-currentcolor-001a.html
highlight-painting-currentcolor-002.html
highlight-painting-currentcolor-002a.html
highlight-painting-currentcolor-002b.html
highlight-painting-currentcolor-003.html
highlight-painting-currentcolor-003a.html
highlight-painting-currentcolor-003b.html
highlight-painting-currentcolor-004.html
highlight-painting-currentcolor-004a.html
highlight-painting-currentcolor-004b.html
highlight-painting-currentcolor-005.html
highlight-painting-shadows-horizontal.html
highlight-painting-shadows-vertical.html
highlight-painting-soft-hyphens-001.html
highlight-painting-soft-hyphens-002-crash.html
highlight-styling-001.html
highlight-styling-002.html
parsing/highlight-pseudos.html
</wpt>
The <dfn export lt="highlight pseudo-element">highlight pseudo-elements</dfn>
represent portions of a document that have been given a particular status
and are typically styled differently to indicate that status to the user.
For example,
selected portions of the document are typically highlighted
(given alternate background and foreground colors, or a color wash)
to indicate their selected status.
The following <a>highlight pseudo-elements</a> are defined:
<dl export>
<dt><dfn>::selection</dfn>
<dd>
The ''::selection'' pseudo-element represents
the portion of a document that has been selected
as the target or object of some possible future user-agent operation(s).
It applies, for example, to selected text within an editable text field,
which would be copied by a copy operation or replaced by a paste operation.
<wpt>
active-selection-001-manual.html
active-selection-002-manual.html
active-selection-004-manual.html
active-selection-011.html
active-selection-012.html
active-selection-014.html
active-selection-016.html
active-selection-018.html
active-selection-025.html
active-selection-027.html
active-selection-056.html
active-selection-057.html
active-selection-063.html
selection-background-color-001.html
selection-link-001.html
selection-link-002.html
selection-link-003.html
selection-over-highlight-001.html
selection-universal-shadow-dom.html
selection-contenteditable-011.html
selection-input-011.html
selection-textarea-011.html
textpath-selection-011.html
</wpt>
<dt><dfn>::target-text</dfn>
<dd>
The ''::target-text'' pseudo-element represents text
directly targeted by the document URL’s [=url/fragment=], if any.
Note: When a [=url/fragment|URL fragment=] targets an element,
the '':target'' pseudo-element can be used to select it,
but ''::target-text'' does not match anything.
It only matches text that is itself targeted by the [[=url/fragment=]].
<wpt>
target-text-001.html
target-text-002.html
target-text-003.html
target-text-004.html
target-text-005.html
target-text-006.html
target-text-007.html
target-text-008.html
target-text-009.html
target-text-010.html
target-text-dynamic-001.html
target-text-dynamic-002.html
target-text-dynamic-003.html
target-text-dynamic-004.html
target-text-shadow-horizontal.html
target-text-shadow-vertical.html
target-text-text-decoration-001.html
</wpt>
<dt><dfn>::spelling-error</dfn>
<dd>
The ''::spelling-error'' pseudo-element represents
a portion of text that has been flagged by the user agent as misspelled.
<wpt>
spelling-error-001.html
spelling-error-002-manual.html
spelling-error-003-manual.html
spelling-error-004-crash.html
spelling-error-005-crash.html
spelling-error-006.html
</wpt>
<dt><dfn>::grammar-error</dfn>
<dd>
The ''::grammar-error'' pseudo-element represents
a portion of text that has been flagged by the user agent as grammatically incorrect.
<wpt>
grammar-error-001.html
grammar-error-002-manual.html
grammar-error-003-manual.html
</wpt>
</dl>
The <a>highlight pseudo-elements</a>
do not necessarily fit into the element tree,
and can arbitrarily cross element boundaries without honoring its nesting structure.
Note: A future level of CSS may introduce ways to create
custom highlight pseudo-elements.
<h3 id="highlight-styling">
Styling Highlights</h3>
The <a>highlight pseudo-elements</a> can only be styled
by a limited set of properties that do not affect layout
and can be applied performantly in a highly dynamic environment--
and additionally (to ensure interoperability)
whose rendering within the [[#highlight-bounds|required area]]
is not dependent on the exact (UA-determined) bounds
of the [=highlight overlay=].
The following properties apply to the <a>highlight pseudo-elements</a>:
<ul>
<li>'color'
<wpt>
active-selection-001-manual.html
active-selection-011.html
active-selection-016.html
active-selection-018.html
</wpt>
<li>'background-color'
<wpt>
active-selection-002-manual.html
active-selection-012.html
active-selection-031.html
</wpt>
<li>'text-decoration' and its associated properties (including 'text-underline-position' and 'text-underline-offset')
<wpt>
active-selection-004-manual.html
active-selection-014.html
active-selection-021.html
grammar-error-001.html
grammar-error-002-manual.html
grammar-error-003-manual.html
spelling-error-001.html
spelling-error-002-manual.html
spelling-error-003-manual.html
</wpt>
<li>'text-shadow'
<wpt>
marker-text-shadow.html
</wpt>
<li>'stroke-color', 'fill-color', and 'stroke-width'
<wpt>
textpath-selection-011.html
</wpt>
<li>[=custom properties=] [[!CSS-VARIABLES-1]]
</ul>
The 'forced-color-adjust' property cannot be set on [=highlight pseudo-elements=];
however a [=highlight pseudo-element=] must honor
any [=forced colors mode=] applied to its [=originating element=]
(and is therefore subject to the control of the [=originating element=]’s 'forced-color-adjust' value).
Issue: Are there any other properties that should be included here?
Note: The 'color' property sets the color of
both the text
and all line decorations (underline, overline, line-through)
and emphasis marks ('text-emphasis')
applied to the text
by the <a>originating element</a> and its ancestors and descendants.
<!-- Add this back if for some reason someone wants to implement 'outline'?
The outline, if supported, must be drawn
around the union of the active portions of the <a>highlight overlay</a>
precisely along the boundaries of those portions
and not between congruent parts.
The UA may use the outline styling of the nearest common ancestor
of any continuous or discontinuous range
rather than piecing together varying styles of outline
into a single shape.
-->
Note: Historically (and at the time of writing)
only 'color' and 'background-color' have been interoperably supported.
<h3 id=highlight-ua-styles>
Default UA Styles</h3>
The following additions are recommended for the default UA stylesheet:
<pre class="lang-css">
/* Represent default spelling/grammar error styling in an adjustable way */
:root::spelling-error { text-decoration-line: spelling-error; }
:root::grammar-error { text-decoration-line: grammar-error; }
</pre>
Some [=highlight pseudo-elements=]
should have <dfn>paired default highlight colors</dfn>--
a default 'color' and 'background-color'
provided by the UA
that are either used or overridden together,
see [[#paired-defaults]].
For ''::selection'' they should correspond to
''HighlightText'' and ''Highlight'',
while for ''::target-text'' they should correspond to
''MarkText'' and ''Mark''.
UAs may apply additional effects to enhance the presentation
of highlighted content,
for example dimming content other than the highlighted text
or transitioning out a highlight style based on user interactions or timing.
These are not controlled by CSS.
ISSUE: UA tweaks to the presentation of highlights
in ways that <em>are</em> controlled by CSS
are currently under discussion
in <a href='https://github.com/w3c/csswg-drafts/issues/6853'>Issue 6853</a>.
<h4 id="paired-defaults">
Paired Defaults</h4>
For compatibility reasons,
[=paired default highlight colors=]
must only be [=used value|used=]
when neither 'color' nor 'background-color'
yield a [=cascaded value=]
from the [=author origin=]
(or inherit their value from the author origin).
When a highlight color is ''revert'' or ''revert-layer'',
the origin <em>after</em> rolling back the cascade
determines the [=cascaded value=]’s [=cascade origin|origin=].
Note: Because this rule is for compatibility reasons,
it does not apply to other similar properties
like 'fill-color' or 'stroke-color'.
<div class="example">
For example,
given the following markup:
<pre class="lang-markup">
<p>Highlight this <em>and this</em>.</p>
</pre>
Any of the following rules
would suppress the default 'background-color'
for ''::selection''
in the <code><em></code> element
if given by the author:
<pre class="lang-css">
em::selection { color: initial; }
em::selection { color: inherit; }
em::selection { color: unset; }
em::selection { color: green; }
p::selection { color: green; }
</pre>
</div>
<wpt>
highlight-cascade/highlight-paired-cascade-001.html
highlight-cascade/highlight-paired-cascade-002.html
highlight-cascade/highlight-paired-cascade-003.html
highlight-cascade/highlight-paired-cascade-004.html
highlight-cascade/highlight-paired-cascade-005.html
highlight-cascade/highlight-paired-cascade-006.html
</wpt>
<h3 id=highlight-bounds>
Area of a Highlight</h3>
<p>For each type of highlighting (see [[#highlight-selectors]])
there exists a single <dfn>highlight overlay</dfn> for the entire document,
the active portions of which are represented
by the corresponding <a>highlight pseudo-element</a>.
Each box owns the piece of the overlay corresponding to any text or replaced content
directly contained by the box.
<ul>
<li>
For text, the corresponding overlay must cover at least the entire em box
and may extend further above/below the em box to the line box edges.
Spacing between two characters may also be part of the overlay area,
in which case it belongs to the innermost element that contains both characters
and is selected when both characters are selected.
<wpt>
selection-intercharacter-011.html
selection-intercharacter-012.html
</wpt>
<li>
For replaced content, the associated overlay must cover at least the entire replaced object,
and may extend outward to include the element's entire content box.
<wpt>
active-selection-043.html
</wpt>
<li>
The overlay may also include other areas within the border-box of an element;
in this case, those areas belong to the innermost such element that contains the area.
<li>
For an [=inline-level box=], the overlay may extend outside its border edges
in the [=block axis=] as far as the edges of its [=line box=].
</ul>
Issue: See
<a href="http://lists.w3.org/Archives/Public/www-style/2008Nov/0022.html">F2F minutes</a>,