-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
1089 lines (916 loc) · 43.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: Exploring
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/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, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Alan Stearns, Adobe Systems Inc., stearns@adobe.com, 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.
Ignored Terms: initial-letter, PseudoElement, pseudo(), selectors
Default Highlight: css
Indent: 2
</pre>
<pre class="link-defaults">
spec:css-color-3; type:value; text:currentcolor
spec:css-color-3; type:property; text:color
spec:fill-stroke-3; type:property; text:stroke-width
</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">
The ::first-line pseudo-element</h3>
The <dfn>::first-line</dfn> pseudo-element describes the contents of
the <a>first formatted line</a> of its <a>originating element</a>.
<div class="example">
The rule below means
“change the letters of the first line of every <code>p</code> element to uppercase”:
<pre>p::first-line { text-transform: uppercase }</pre>
The selector ''p::first-line''
does not match any real document element.
It does match a pseudo-element that conforming user agents
will 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">
For example, given an ordinary HTML [[HTML5]] paragraph such as:
<pre>
<P>This is a somewhat long HTML
paragraph that will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
</pre>
The lines might be broken as follows:
<pre>
THIS IS A SOMEWHAT LONG HTML PARAGRAPH THAT
will be broken into several lines. The first
line will be identified by a fictional tag
sequence. The other lines will be treated as
ordinary lines in the paragraph.
</pre>
This paragraph might be “rewritten” by user agents
to include a <dfn>fictional tag sequence</dfn> to represent ''::first-line''.
This <a>fictional tag sequence</a> helps to show how properties are inherited.
<pre>
<P><b><P::first-line></b> This is a somewhat long HTML
paragraph that <b></P::first-line></b> will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
</pre>
</div>
If a pseudo-element breaks up a real element,
the desired effect can often be described by a <a>fictional tag sequence</a>
that closes and then re-opens the element.
<div class="example">
Thus, if we mark up the previous paragraph with a <code>span</code>
element encompassing the first sentence:
<pre>
<P><b><SPAN class="test"></b> This is a somewhat long HTML
paragraph that will be broken into several
lines.<b></SPAN></b> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
</pre>
the user agent could simulate start and end tags for <code>span</code>
when inserting the <a>fictional tag sequence</a> for ''::first-line''
to get the correct inheritance behavior.
<pre>
<P><P::first-line><b><SPAN class="test"></b> This is a somewhat long HTML
paragraph that will <b></SPAN></b></P::first-line><b><SPAN class="test"></b> be broken into several
lines.<b></SPAN></b> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
</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 an element
must occur inside a block-level descendant in the same flow
(i.e., a block-level descendant that is not out-of-flow due to floating or positioning).
<div class="example">
For example, the first line of the <code>DIV</code> in <code><DIV><P>This line...</P></DIV></code>
is the first line of the <code>P</code>
(assuming that both <code>P</code> and <code>DIV</code> are blocks).
</div>
The first line of a table-cell or inline-block
cannot be the first formatted line of an ancestor element.
Thus, in <code><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".
Note: Note that the first line of the <code>p</code> in this fragment:
<code><p><br>First...</code>
doesn't contain any letters (assuming the default style for <code>br</code>).
The word "First" is not on the first formatted line.
A user agent must act as if the fictional start tags of a ''::first-line'' pseudo-element
were nested just inside the innermost enclosing block-level element.
<div class="example">
For example, the <a>fictional tag sequence</a> for
<pre>
<DIV>
<P>First paragraph</P>
<P>Second paragraph</P>
</DIV>
</pre>
is
<pre>
<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 element, but with certain restrictions.
The following CSS properties apply to a ''::first-line'' pseudo-element:
<ul>
<li>all font properties (see [[CSS-FONTS-3]])
<li>the 'color' and 'opacity' properties (see [[CSS-COLOR-3]])
<li>all background properties (see [[CSS-BACKGROUNDS-3]])
<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>
<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.)
<h3 id="first-letter-pseudo">
The ::first-letter pseudo-element</h3>
The <dfn>::first-letter</dfn> pseudo-element represents
the first <a>typographic letter unit</a> [[!CSS-TEXT-3]]
on the <a>first formatted line</a> of its <a>originating element</a>,
if it is not preceded by any other content
(such as images or inline tables) on its line.
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>h2 + p::first-letter { initial-letter: 2; }
</pre>
</div>
Punctuation (i.e, characters that belong to the Punctuation (<code>P*</code>) <a>Unicode general category</a> [[!UAX44]])
that precedes or follows the first <a>typographic letter unit</a>
and any intervening space separators
(characters that belong to the <code>Zs</code> Unicode general category [[!UAX44]])
must also be included
in the ''::first-letter'' pseudo-element.
<div class="figure">
<img alt="Quotes that precede the first letter should be included." src="images/first-letter2.gif">
</div>
As explained in [[!CSS-TEXT-3]],
a <a>typographic letter 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]]
The UA should tailor its definition of <a>typographic letter unit</a>
to reflect the first-letter traditions of the ''::first-letter'' pseudo-element’s <em>containing block</em>’s content language.
Note: Note that the first <a>typographic letter unit</a> may in fact
be a digit, e.g., the “6” in “67 million dollars is a lot of money.”
If the characters that would form the ''::first-letter''
are not in the same element, such as <code>‘T</code> in <code><p>‘<em>T...</code>,
the user agent may create a ''::first-letter'' pseudo-element
from one of the elements, both elements, or simply not create a pseudo-element.</code>
Additionally, if the first letter(s) of the block
are not at the start of the line (for example due to bidirectional reordering),
then the user agent need not create the pseudo-element(s).
The ''::first-letter'' pseudo-element is contained within any ''::first-line''
pseudo-elements, and thus inherits from ''::first-line''.
<h4 id="first-letter-application">
Finding the First Letter</h4>
The first letter must occur on the <a>first formatted line</a>.
For example, in this HTML fragment: <code><p><br>First...</code>
the first line doesn't contain any letters
and ''::first-letter'' doesn't match anything.
In particular, it does not match the “F” of “First”.
In CSS, the ''::first-letter'' pseudo-element
only applies to block containers.
<span class="note">A future version of this specification
may allow this pseudo-element to apply to more display types.</span>
The ''::first-letter'' pseudo-element can be used
with all such elements that contain text,
or that have a descendant in the same flow that contains text.
A user agent should act as if the fictional start tag
of the ::first-letter pseudo-element
is just before the first text of the element,
even if that first text is in a descendant.
<div class="example">
Example:
The <a>fictional tag sequence</a> for this HTML fragment:
<pre>
<div>
<p>The first text.
</pre>
is:
<pre>
<div>
<p><div::first-letter><p::first-letter>T</...></...>he first text.
</pre>
</div>
In CSS the first letter of a table-cell or inline-block
cannot be the first letter of an ancestor element.
Thus, in <code><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.
If an element is a list item (''display: list-item''),
the ''::first-letter'' applies
to the first letter in the principal box <em>after</em> the marker.
User-Agents may ignore ''::first-letter''
on list items with ''list-style-position: inside''.
If an element has ''::before'' or ''::after'' content,
the ''::first-letter'' applies to the first letter of the
element <em>including</em> that content.
<div class="example">
Example:
After the rule ''p::before {content: "Note: "}'', the
selector ''p::first-letter'' matches the "N" of "Note".
</div>
<h4 id="first-letter-styling">
Styling the ''::first-letter'' Pseudo-element</h4>
In CSS a ::first-letter pseudo-element is similar to an inline-level element.
The following properties that apply to ''::first-letter'' pseudo-elements:
<ul>
<li>all font properties (see [[CSS-FONTS-3]])
<li>the 'color' and 'opacity' properties (see [[CSS-COLOR-3]])
<li>all background properties (see [[CSS-BACKGROUNDS-3]])
<li>any typesetting properties that apply to inline elements (see [[CSS-TEXT-3]])
<li>all text decoration properties (see [[CSS-TEXT-DECOR-3]])
<li>any inline layout properties that apply to inline elements (see [[CSS-INLINE-3]])
<li>margin and padding properties (see [[CSS2]])
<li>border properties and 'box-shadow' (see [[CSS-BACKGROUNDS-3]])
<li>any other properties defined to apply to ''::first-letter''
by their respective specifications
</ul>
User agents may apply other properties as well.
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,
approximate font sizes,
or to take the glyph outline into account when formatting.
This possibility has been intentionally removed,
as it proved to be a poor solution for the intended use case (Drop Caps),
yet caused interoperability problems.
<div class="example">
Example:
This CSS and HTML example shows a possible rendering of an initial cap.
Note that the fictional start tag of the first letter
is inside the <span>span</span>,
and thus the font weight of the first letter is normal,
not bold as the <span>span</span>:
<pre>
p { line-height: 1.1 }
p::first-letter { font-size: 3em; font-weight: normal }
span { font-weight: bold }
...
<p><span>Het hemelsche</span> gerecht heeft zich ten lange lesten<br>
Erbarremt over my en mijn benaeuwde vesten<br>
En arme burgery, en op mijn volcx gebed<br>
En dagelix geschrey de bange stad ontzet.
</pre>
<div class="figure">
<img alt="Image illustrating the ::first-letter pseudo-element" src="images/initial-cap.png">
</div>
</div>
<div class="example">
The following CSS will make a drop cap initial letter span about two lines:
<pre>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
<HEAD>
<TITLE>Drop cap initial letter</TITLE>
<STYLE type="text/css">
P { font-size: 12pt; line-height: 1.2 }
P::first-letter { font-size: 200%; font-weight: bold; float: left }
SPAN { text-transform: uppercase }
</STYLE>
</HEAD>
<BODY>
<P><SPAN>The first</SPAN> few words of an article
in The Economist.</P>
</BODY>
</HTML>
</pre>
This example might be formatted as follows:
<div class="figure">
<img alt="Image illustrating the combined effect of the ::first-letter
and ::first-line pseudo-elements" src="images/first-letter.gif">
</div>
The <a>fictional tag sequence</a> is:
<pre>
<P>
<SPAN>
<P::first-letter>
T
</P::first-letter>he first
</SPAN>
few words of an article in the Economist.
</P>
</pre>
Note that the ''::first-letter'' pseudo-element tags abut the
content (i.e., the initial character), while the ::first-line
pseudo-element start tag is inserted right after the start tag of the
block element.
</div>
<h2 id="highlight-pseudos">
Highlight Pseudo-elements</h2>
<h3 id="highlight-selectors">
Selecting Highlighted Content: the ''::selection'', ''::inactive-selection'', ''::target-text'', ''::spelling-error'', and ''::grammar-error'' pseudo-elements</h3>
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>
<wpt>
css/css-pseudo/active-selection-063.html
css/css-pseudo/textpath-selection-011.html
</wpt>
<dt><dfn>::inactive-selection</dfn>
<dd>
The ''::selection'' and ''::inactive-selection'' pseudo-elements represent
the portion of a document that has been selected
as the target or object of some possible future user-agent operation(s).
They apply, for example, to selected text within an editable text field,
which would be copied by a copy operation or replaced by a paste operation.
''::selection'' applies to active selections,
whereas ''::inactive-selection'' applies to inactive selections
(e.g. when the document window is inactive and therefore not receiving events).
<dt><dfn>::target-text</dfn>
<dd>
The ''::target-text'' pseudo-element represents text
directly targetted by the document URL’s [=URL/fragment=], if any.
Note: When a [=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 targetted by the [[=URL/fragment=]].
<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>
css/css-pseudo/spelling-error-001.html
css/css-pseudo/spelling-error-002-manual.html
css/css-pseudo/spelling-error-003-manual.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>
css/css-pseudo/grammar-error-001.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.
<!-- ALSO: are not dependent on the exact bounds of the selection painting area,
and can be applied performantly in a highly dynamic environment-->
The following properties apply to the <a>highlight pseudo-elements</a>:
<ul>
<li>'color'
<li>'background-color'
<li>'cursor'
<li>'caret-color'
<li>'text-decoration' and its associated properties
<wpt>
css/css-pseudo/grammar-error-001.html
css/css-pseudo/spelling-error-001.html
css/css-pseudo/spelling-error-002-manual.html
css/css-pseudo/spelling-error-003-manual.html
</wpt>
<li>'text-shadow'
<wpt>
css/css-pseudo/selection-text-shadow-006-manual.html
css/css-pseudo/selection-text-shadow-016.html
</wpt>
<li>'stroke-color', 'fill-color', and 'stroke-width'
<wpt>
css/css-pseudo/textpath-selection-011.html
</wpt>
</ul>
Issue: Are there any other properties that should be included here?
The 'color' property specifies 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; }
/* Highlight targetted text */
:root::target-text { color: MarkText; background: Mark; }
</pre>
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.
<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.
<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.
<li>
The overlay may also include other 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>,
<a href="http://lists.w3.org/Archives/Public/www-style/2008Oct/0268.html">dbaron's message</a>,
<a href="http://lists.w3.org/Archives/Public/www-style/2010May/0247.html">Daniel's thread</a>,
<a href="http://lists.w3.org/Archives/Public/www-style/2010May/0261.html">Gecko notes</a>,
<a href="http://lists.w3.org/Archives/Public/www-style/2010May/0366.html">Opera notes</a>,
<a href="http://lists.w3.org/Archives/Public/www-style/2010May/0280.html">Webkit notes</a>
Issue: Not sure if this is the correct way of describing the way things work.
<h3 id=highlight-cascade>
Cascading and Per-Element Highlight Styles</h3>
Each element draws its own active portions of the <a>highlight overlays</a>,
which receives the styles specified by
the corresponding <a>highlight pseudo-element</a> styles
for which that element is the <a>originating element</a>.
When multiple styles conflict,
the winning style is determined by the cascade.
When any supported property is not given a value by the cascade,
it's value is determined by inheritance from
the corresponding <a>highlight pseudo-element</a>
of its <a>originating element</a>'s parent element
(regardless of whether that property is an <a>inherited property</a>).
<wpt>
css/css-pseudo/cascade-highlight-004.html
</wpt>
<div class="example">
For example, if the following rules were applied:
<pre>
p::selection { color: yellow; background: green; }
p > em::selection { color: orange; }
em::selection { color: red; }
</pre>
to the following markup:
<pre>
<p>Highlight this <em>and this</em>.</p>
</pre>
The selection highlight would be green throughout,
with yellow text outside the <code><em></code> element
and orange text inside it.
</div>
<wpt>
css/css-pseudo/cascade-highlight-001.html
</wpt>
<p class="advisement">
Authors wanting multiple selections styles should use
<strong>'':root::selection''</strong>
for their document-wide selection style,
since this will allow clean overriding in descendants.
''::selection'' alone applies to every element in the tree,
overriding the more specific styles of any ancestors.
<div class="example">
For example, if an author specified
<pre>
::selection { background: blue; }
p.warning::selection { background: red; }
</pre>
and the document included
<pre>
<p class="warning">Some <strong>very important information</strong></p>
</pre>
The highlight would be blue over “very important information”
because the <code><strong></code> element´s ''::selection''
also matches the ''::selection { background: blue; }'' rule.
(Remember that ''*'' is implied when a tag selector is missing.)
The style rules that would give the intended behavior
(red highlight within <code>p.warning</code>, blue elsewhere) are
<pre>
:root::selection { background: blue; }
p.warning::selection { background: red; }
</pre>
</div>
<wpt>
css/css-pseudo/cascade-highlight-002.html
</wpt>
The UA should use the OS-default highlight colors for ''::selection''
when neither 'color' nor 'background-color' has been specified by the author.
Note: This paired-cascading behavior
does not allow using the normal cascade
(i.g. '':root::selection'' rules in the <a>UA style sheet</a>)
to represent the OS default selection colors.
However it has been interoperably implemented in browsers
and is thus probably a Web-compatibility requirement.
<h3 id="highlight-painting">
Painting the Highlight</h3>
<h4 id="highlight-backgrounds">
Backgrounds</h4>
Each <a>highlight pseudo-element</a> draws its background
over the corresponding portion of the <a>highlight overlay</a>,
painting it
immediately below any positioned descendants
(i.e. just before step 8 in <a href="https://www.w3.org/TR/CSS22/zindex.html#painting-order">CSS2.2§E.2</a>).
<!-- Its outline, if any, is painted immediately over its background. -->
The ''::selection'' overlay is drawn
over the ''::target-text'' overlay which is drawn
over the ''::spelling-error'' overlay
which is drawn over the ''::grammar-error'' overlay.
<wpt>
css/css-pseudo/highlight-z-index-001.html
css/css-pseudo/highlight-z-index-002.html
</wpt>
<h4 id="highlight-shadows">
Shadows</h4>
Any 'text-shadow' applying to a [=highlight pseudo-element=]
is drawn over its corresponding [=highlight overlay=] background.
Such text shadows also stack over each other
(and over any original 'text-shadow' applied to the text and its decorations,
which continues to apply).
Note: Since each [=highlight overlay=] background
is drawn over any shadows belonging to the layer(s) below,
a [=highlight overlay=] background can obscure lower-level shadows.
<h4 id="highlight-text">
Text and Text Decorations</h4>
A <a>highlight pseudo-element</a>
suppresses the normal drawing of any associated text
(and any text decorations applied to that text).
Instead the topmost active <a>highlight overlay</a>
redraws that text
(and its decorations)
over the <a>highlight overlay</a> backgrounds
<!-- (and outlines, if any) -->
using its own 'color'.
For this purpose,
''currentColor'' on a [=highlight pseudo-element=]’s 'color' property represents
the 'color' of the next <a>highlight pseudo-element</a> layer below,
falling back finally to the colors that would otherwise have been used
(those applied by the [=originating element=] or
an intervening [=pseudo-element=] such as ''::first-line'' or ''::first-letter'').
Any text decorations introduced by each <a>highlight pseudo-element</a>
are stacked in the same order as their backgrounds
over the text’s original decorations
and are all drawn, in their own colors.
Note: The element’s own text decorations
(both <a href="https://www.w3.org/TR/css-text-decor/#line-decoration">line decorations</a>
and <a href="https://www.w3.org/TR/css-text-decor/#emphasis-marks">emphasis marks</a>)
are thus drawn in the pseudo-element’s own 'color'
when that is not ''currentColor'',
regardless of their original color or fill specifications.
<h4 id="highlight-replaced">
Replaced Elements</h4>
For non-replaced content, the UA must honor the 'color' and 'background-color'
(including their alpha channels) as specified.
However, for replaced content, the UA should create a semi-transparent wash
to coat the content so that it can show through the selection.
This wash should be of the specified 'background-color' if that is not ''transparent'',
else of the specified 'color';
however the UA may adjust the alpha channel.
<h3 id="highlight-security">
Security and Privacy Considerations</h3>
Because the styling of spelling and grammar errors
can leak information about the contents of a user's dictionary
(which can include the user's name and even includes the contents of his/her address book!)
UAs that implement ''::spelling-error'' and ''::grammar-error''
must prevent pages from being able to read
the styling of such highlighted segments.
<h2 id="treelike">
Tree-Abiding Pseudo-elements</h2>
<dfn export lt="tree-abiding|tree-abiding pseudo-element">Tree-abiding pseudo-elements</dfn> always fit within the box tree.
They <a lt="inheritance">inherit</a> any inheritable properties from their <a>originating element</a>;
non-inheritable properties take their <a>initial values</a> as usual.
[[CSS-CASCADE-4]]
<h3 id="generated-content">
Generated Content Pseudo-elements: ''::before'' and ''::after''</h3>
When their computed 'content' value is not ''content/none'',
these pseudo-elements generate boxes
as if they were immediate children of their <a>originating element</a>,
with content as specified by 'content'.
<dl>
<dt><dfn>::before</dfn>
<dd>Represents a styleable child pseudo-element
immediately before the <a>originating element</a>'s actual content.
<dt><dfn>::after</dfn>
<dd>Represents a styleable child pseudo-element
immediately after the <a>originating element</a>'s actual content.
</dl>
These pseudo-elements can be styled
exactly like any normal document-sourced element in the document tree;
all properties that apply to a normal element
likewise apply to ''::before'' and ''::after''.
<div class="example">
For example, the following rule inserts the string “Note: ”
before the content of every <code><p></code> element
whose <code>class</code> attribute has the value <code>note</code>:
<pre>p.note::before { content: "Note: " }</pre>
Since the initial value of 'display' is ''display/inline'',
this will generate an inline box.
Like other inline children of <code><p></code>,
it will participate in <code><p></code>’s inline formatting context,
potentially sharing a line with other content.
</div>
As with the content of regular elements,
the generated content of ''::before'' and '':after'' pseudo-elements
can form part of any ''::first-line'' and ''::first-letter'' pseudo-elements
applied to its <a>originating element</a>.
<h3 id="marker-pseudo">
List Markers: the ''::marker'' pseudo-element</h3>
The <dfn>::marker</dfn> pseudo-element represents
the automatically generated [=marker box=] of a [=list item=].
(See [[CSS-DISPLAY-3]] and [[CSS-LISTS-3]].)
Inheritance for a ''::marker'' pseudo-element ignores any ''::first-line'' styles
and the contents of a ''::marker'' are ignored (not selected) by ''::first-letter''.
Only a limited set of properties can be used on the ''::marker'' pseudo-element.
This list is defined in [[css-lists-3#marker-properties]].
The ''::before::marker'' or ''::after::marker'' selectors
are valid and
can be used to represent the [=marker boxes=]
of ''::before'' or ''::after'' pseudo-elements that happen to be [=list items=].
However ''::marker::marker'' is invalid,
and the computed value of 'display' on ''::marker''
loses its ''display/list-item'' aspect.
<h3 id="placeholder-pseudo">
Placeholder Input: the ''::placeholder'' pseudo-element</h3>
The <dfn>::placeholder</dfn> pseudo-element represents
placeholder text in an input field:
text that represents the input
and provides a hint to the user on how to fill out the form.
For example, a date-input field
might have the placeholder text “YYYY/MM/DD”
to clarify that numeric dates are to be entered in year-month-day order.
Note: There also exists a '':placeholder-shown'' pseudo-<em>class</em>,
which applies to (real) elements while they are showing placeholder text,
and can be used to style such elements specially.
''::placeholder'' specifically selects
a pseudo-element representing the placeholder <em>text</em>,
and is thus relatively limited in its abilities.
All properties that apply to the ''::first-line'' pseudo-element
also apply to the ''::placeholder'' pseudo-element.
In interactive media, placeholder text is often hidden once the user has entered input;
however this is not a requirement, and both the input value and the placeholder text may be visible simultaneously.
The exact behavior is UA-defined.
Note that in static media (such as print)
placeholder text will be present even after the user has entered input.
Issue: Authors seem to want 'text-align' on the list of supported properties.
See e.g. <a href="http://css-tricks.com/almanac/selectors/p/placeholder/">comments here</a>.
Note: It's been requested that ''::placeholder'' also refer to
a placeholder which has a corresponding element in the element tree.
It's not clear how this should work, but it may be worth doing.
See <a href="https://github.com/w3c/csswg-drafts/issues/2517">Issue 2417</a>.
<h2 id="interactions">
Overlapping Pseudo-element Interactions</h2>
<div class="example" id="overlapping-example">
Recall that
<ul>
<li>
the contents of ''::before'' and ''::after'' are selected
exactly as if they were normal elements in the document source tree
<li>
the ''::first-letter'' boundaries are tightly wrapped around the first letter text,
and ''::first-letter'' is constrained to exist solely on the first formatted line.
<li>
the ''::first-line'' start is inserted just inside the containing block's element boundary,
and its end after the close of all content on the line
</ul>
The following CSS and HTML example
illustrates how overlapping pseudo-elements interact:
<xmp class="lang-html">
<style>
p { color: red; font-size: 12pt }
p::first-letter { color: green; font-size: 200% }
p::first-line { color: blue }
</style>
<p>Some text that ends up on two lines</p>
</xmp>
The first letter of each P element will be green with a font size of ’24pt'.
The rest of the first formatted line will be blue
while the rest of the paragraph will be red.
Assuming that a line break will occur before the word "ends",
the <a>fictional tag sequence</a> for this fragment might be:
<xmp class="lang-html">
<p>
<p::first-line>
<p::first-letter>
S
</p::first-letter>
ome text that
</p::first-line>
ends up on two lines
</p>
</xmp>
</div>
<h2 id="cssom">
Additions to the CSS Object Model</h2>
<h3 id="CSSPseudoElement-interface">
{{CSSPseudoElement}} Interface</h3>
The {{CSSPseudoElement}} interface
allows pseudo-elements to be event targets.
<pre class="idl">
[Exposed=Window]
interface CSSPseudoElement : EventTarget {
readonly attribute CSSOMString type;
readonly attribute Element element;
};
</pre>
The <dfn attribute for=CSSPseudoElement>type</dfn> attribute
is a string representing the type of the pseudo-element.
This can be one of the following values:
<dl>
<dt><code>"::before"</code>
<dd>Represents the ''::before'' pseudo-element.
<dt><code>"::after"</code>
<dd>Represents the ''::after'' pseudo-element.
<dt><code>"::marker"</code>
<dd>Represents the ''::marker'' pseudo-element.
</dl>
The <dfn attribute for=CSSPseudoElement>element</dfn> attribute is the
[=originating element=] of the pseudo-element.
Note: This interface may be extended in the future
to other pseudo-element types
and/or to allow setting style information
through a {{CSSStyleDeclaration}} <code>style</code> attribute.
The current functionality is limited
to that which is needed to support [[web-animations-1]].
<h3 id="window-interface">
{{pseudo()}} method of the {{Element}} interface</h3>
A new method is added to the {{Element}} interface to retrieve
pseudo-elements created by a given element for a given type:
<pre class="idl">
partial interface Element {
CSSPseudoElement? pseudo(CSSOMString type);
};
</pre>
<div algorithm>
The <dfn method for=Element title="pseudo(type)" id="dom-element-pseudo">pseudo(CSSOMString type)</dfn> method
is used to retrieve the {{CSSPseudoElement}} instance
of the type matching {{type!!argument}}
associated with the element.
When it is called,