-
Notifications
You must be signed in to change notification settings - Fork 689
/
Copy pathOverview.bs
1630 lines (1356 loc) · 61.6 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 Lists Module Level 3
Shortname: css-lists
Level: 3
Group: CSSWG
Status: ED
Work Status: Refining
ED: https://drafts.csswg.org/css-lists-3/
TR: https://www.w3.org/TR/css-lists-3/
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Tab Atkins, Google, http://xanthir.com/contact/, w3cid 42199
Former Editor: Ian Hickson, Google, [email protected]
Former Editor: Tantek Çelı̇k, Formerly of Microsoft, [email protected]
Previous Version: https://www.w3.org/TR/2020/WD-css-lists-3-20200709/
Previous Version: https://www.w3.org/TR/2019/WD-css-lists-3-20190817/
Previous Version: https://www.w3.org/TR/2019/WD-css-lists-3-20190425/
Previous Version: https://www.w3.org/TR/2014/WD-css-lists-3-20140320/
Previous Version: https://www.w3.org/TR/2011/WD-css3-lists-20110524/
!Contributors: Simon Montagu, AOL-TW/Netscape, <a href="mailto:[email protected]">[email protected]</a>
!Contributors: Daniel Yacob, <a href="mailto:[email protected]">[email protected]</a>
!Contributors: Christopher Hoess, <a href="mailto:[email protected]">[email protected]</a>
!Contributors: Daniel Glazman, AOL-TW/Netscape, <a href="mailto:[email protected]">[email protected]</a>
Abstract: This module contains CSS features related to list counters: styling them, positioning them, and manipulating their value.
</pre>
<pre class='link-defaults'>
spec:css-pseudo-4; type:selector; text:::before
spec:infra; type:dfn;
text:list
text:string
</pre>
<h2 id='intro'>
Introduction</h2>
This specification defines the ''::marker'' pseudo-element,
the ''list-item'' <a>display type</a> that generates markers,
and several properties controlling the placement and styling of markers.
It also defines <a>counters</a>,
which are special numerical objects
often used to generate the default contents of markers.
<div class="example">
For instance, the following example illustrates
how markers can be used to add parentheses around each numbered list item:
<xmp highlight=html>
<style>
li::marker { content: "(" counter(list-item, lower-roman) ")"; }
li { display: list-item; }
</style>
<ol>
<li>This is the first item.
<li>This is the second item.
<li>This is the third item.
</ol>
</xmp>
It should produce something like this:
<pre>
(i) This is the first item.
(ii) This is the second item.
(iii) This is the third item.
</pre>
Note: Note that this example is far more verbose than is usually needed in HTML,
as the UA default style sheet takes care of most of the necessary styling.
</div>
With descendant selectors and child selectors,
it's possible to specify different marker types depending on the depth of embedded lists.
<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='declaring-a-list-item'>
Declaring a List Item</h2>
A <dfn export>list item</dfn> is any element with its 'display' property set to ''display/list-item''.
<a>List items</a> generate ''::marker'' pseudo-elements;
no other elements do.
Additionally, <a>list items</a> automatically increment an implied ''list-item'' <a>counter</a>
(see [[#list-item-counter]]).
<!--
██ ██ ███ ████████ ██ ██ ████████ ████████ ██████
███ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ███ ██ ██ ██ ████████ █████ ██████ ████████ ██████
██ ██ █████████ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ████████ ██ ██ ██████
-->
<h2 id='markers'>
Markers</h2>
The defining feature of the <a>list item</a> <a>display type</a>
is its <dfn lt="marker | marker box" export>marker</dfn>,
a symbol or ordinal that helps denote the beginning of each <a>list item</a> in a list.
In the CSS layout model,
<a>list item</a> <a>markers</a> are represented by
a <a>marker box</a> associated with each <a>list item</a>.
The contents of this <a>marker</a> can be controlled with
the 'list-style-type' and 'list-style-image' properties on the <a>list item</a>
and by assigning properties to its ''::marker'' pseudo-element.
<h3 id='marker-pseudo'>
The ''::marker'' Pseudo-Element</h3>
The <a>marker box</a> is generated by
the ''::marker'' pseudo-element of a <a>list item</a>
as the [=list item’s=] first child,
before the ''::before'' pseudo-element
(if it exists on the element).
It is filled with content
as defined in [[#content-property]].
<div class="example">
In this example, markers are used to number paragraphs that are designated as "notes":
<xmp highlight=html>
<style>
p { margin-left: 12 em; }
p.note {
display: list-item;
counter-increment: note-counter;
}
p.note::marker {
content: "Note " counter(note-counter) ":";
}
</style>
<p>This is the first paragraph in this document.
<p class="note">This is a very short document.
<p>This is the end.
</xmp>
It should render something like this:
<pre>
This is the first paragraph
in this document.
Note 1: This is a very short
document.
This is the end.
</pre>
</div>
<div class="example">
By using the ''::marker'' pseudo-element,
a list's markers can be styled
independently from the text of the list item itself:
<xmp highlight=html>
<style>
p { margin-left: 8em } /* Make space for counters */
li { list-style-type: lower-roman; }
li::marker { color: blue; font-weight:bold; }
</style>
<p>This is a long preceding paragraph ...
<ol>
<li>This is the first item.
<li>This is the second item.
<li>This is the third item.
</ol>
<p>This is a long following paragraph ...
</xmp>
The preceding document should render something like this:
<pre>
This is a long preceding
paragraph ...
<span style=color:blue;font-weight:bold;>i.</span> This is the first item.
<span style=color:blue;font-weight:bold;>ii.</span> This is the second item.
<span style=color:blue;font-weight:bold;>iii.</span> This is the third item.
This is a long following
paragraph ...
</pre>
Previously the only way to style a marker was through inheritance;
one had to put the desired marker styling on the list item,
and then revert that on a wrapper element around the list item's actual contents.
</div>
<a>Marker boxes</a> only exist for <a>list items</a>:
on any other element,
the ''::marker'' pseudo-element's 'content' property must compute to ''content/none'',
which suppresses its creation.
<h4 id='marker-properties'>
Properties Applying to ''::marker''</h4>
All properties can be set on a ''::marker'' pseudo-element
and will have a [=computed value=];
however,
only the following CSS properties
actually apply to a [=marker box=]:
<ul>
<li>the 'text-combine-upright', 'unicode-bidi', and 'direction' properties (see [[CSS-WRITING-MODES-3]])
<li>the 'content' property (see [[#content-property]], below)
<li>all animation and transition properties (see [[CSS-ANIMATIONS-1]] and [[CSS-TRANSITIONS-1]])
</ul>
<p class="note">
It is expected that future specifications will extend this list of properties;
however at the moment outside marker box layout is not fully defined,
so only these properties are allowed.
Other properties must not have an effect on the [=marker box=]
when set in the [=author origin=] of the [=cascade=].
UAs may either treat such properties as not applying,
or enforce their value by setting a [=user-agent origin=] ''!important'' rule.
However, inheritable properties that apply to text
can be set on the ''::marker'' pseudo-element:
these will inherit to and take effect on its text contents.
<div class=example>
Examples of properties that apply to text,
and therefore to the contents of ''::marker'' when declared on ''::marker'':
<ul>
<li>'white-space', 'text-transform', 'letter-spacing' (see [[CSS-TEXT-3]])
<li>all font properties (see [[CSS-FONTS-3]] and its successors)
<li>the 'color' property (see [[CSS-COLOR-3]])
</ul>
</div>
UAs must add the following rule to their default style sheet:
<pre>
::marker, ::before::marker, ::after::marker {
unicode-bidi: isolate;
font-variant-numeric: tabular-nums;
white-space: pre;
text-transform: none;
}
</pre>
Note: Although the ''::marker'' pseudo-element can represent
the [=marker box=] of a ''::before'' or ''::after'' pseudo-element,
the [=compound selector=] ''::marker'',
which expands to ''*::marker'' [[SELECTORS-4]],
will not select these markers--
an [=originating element=] that is a [=pseudo-element=]
needs to be explicitly specified in the [=selector=],
e.g. ''::before::marker''.
ISSUE: ''white-space: pre'' doesn't have quite the right behavior;
''text-space-collapse: preserve-spaces'' + ''text-space-trim: discard-after''
might be closer to what's needed here.
See discussion in <a href="https://github.com/w3c/csswg-drafts/issues/4448">Issue 4448</a>
and <a href="https://github.com/w3c/csswg-drafts/issues/4891">Issue 4891</a>.
<h3 id='content-property'>
Generating Marker Contents</h3>
The contents of a <a>marker box</a>
are determined by the first of these conditions that is true:
<dl class=switch>
<dt>'content' on the ''::marker'' itself is not ''content/normal''
<dd>
The contents of the <a>marker box</a>
are determined as defined by the 'content' property,
exactly as for ''::before''.
<dt>'list-style-image' on the [=originating element=] defines a [=marker image=]
<dd>
The '<a>marker box</a> contains
an <a>anonymous</a> <a>inline</a> <a>replaced element</a>
representing the specified [=marker image=],
followed by a <a>text run</a> consisting of a single space (U+0020 SPACE).
<dt>'list-style-type' on the [=originating element=] defines a [=marker string=]
<dd>
The <a>marker box</a> contains
a [=text run=] consisting of the specified [=marker string=].
<dt>otherwise
<dd>
The <a>marker box</a> has no contents
and ''::marker'' does not generate a box.
</dl>
Additionally, the UA may transform into spaces or discard
any preserved [=forced line breaks=].
<!--
██ ██████ ████ ██ ██ ███ ██████ ████████
██ ██ ██ ██ ███ ███ ██ ██ ██ ██ ██
██ ██ ██ ████ ████ ██ ██ ██ ██
██ ███████ ██████ ███████ ██ ██ ███ ██ ██ ██ ██ ████ ██████
██ ██ ██ ██ ██ █████████ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████████ ██████ ████ ██ ██ ██ ██ ██████ ████████
-->
<h3 id='image-markers'>
Image Markers: the 'list-style-image' property</h3>
<pre class="propdef">
Name: list-style-image
Value: <<image>> | none
Initial: none
Applies to: <a>list items</a>
Inherited: yes
Percentages: n/a
Computed value: the keyword ''list-style-image/none''or the computed <<image>>
Animation type: discrete
</pre>
Specifies the <dfn>marker image</dfn>,
which is used to fill the [=list item’s=] [=marker=]
when its 'content' is ''content/normal''.
The values are as follows:
<dl dfn-type="value" dfn-for="list-style-image">
<dt><dfn><<image>></dfn>
<dd>
If the <<image>> represents a [=valid image=],
specifies the element's <a>marker image</a> as the <<image>>.
Otherwise,
the element has no [=marker image=].
<dt><dfn>none</dfn>
<dd>
The element has no <a>marker image</a>.
</dl>
<div class="example">
The following example sets the marker at the beginning of each list item to
be the image "ellipse.png".
<pre highlight=css>li { list-style-image: url("http://www.example.com/ellipse.png") }</pre>
</div>
<!--
██ ██████ ████████ ██ ██ ████████ ████████
██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ████ ██ ██ ██
██ ███████ ██████ ███████ ██ ██ ████████ ██████
██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██
████████ ██████ ██ ██ ██ ████████
-->
<h3 id='text-markers'>
Text-based Markers: the 'list-style-type' property</h3>
<pre class="propdef">
Name: list-style-type
Value: <<counter-style>> | <<string>> | none
Initial: disc
Applies to: <a>list items</a>
Inherited: yes
Percentages: n/a
Computed value: specified value
Animation type: discrete
</pre>
Specifies the <dfn>marker string</dfn>,
which is used to fill the <a>list item</a>’s <a>marker</a>
when its 'content' value is ''content/normal''
and there is no [=marker image=].
The values are as follows:
<dl dfn-type="value" dfn-for="list-style-type">
<dt><dfn><<counter-style>></dfn>
<dd>
Specifies the element’s <a>marker string</a> as
the value of the ''counter()/list-item'' counter
represented using the specified <<counter-style>>.
Specifically,
the <a>marker string</a> is
the result of <a lt="generate a counter representation">generating a counter representation</a>
of the ''counter()/list-item'' counter value
using the specified <<counter-style>>,
prefixed by the '@counter-style/prefix' of the <<counter-style>>,
and followed by the '@counter-style/suffix' of the <<counter-style>>.
If the specified <<counter-style>> does not exist,
''decimal'' is assumed.
<dt><dfn><<string>></dfn>
<dd>
The element’s <a>marker string</a> is the specified <<string>>.
<dt><dfn>none</dfn>
<dd>
The element has no <a>marker string</a>.
</dl>
<div class='example'>
The following examples illustrate how to set markers to various values:
<pre highlight=css>
ul { list-style-type: "★"; }
/* Sets the marker to a "star" character */
p.note {
display: list-item;
list-style-type: "Note: ";
list-style-position: inside;
}
/* Gives note paragraphs a marker consisting of the string "Note: " */
ol { list-style-type: upper-roman; }
/* Sets all ordered lists to use the upper-roman counter-style
(defined in the Counter Styles specification [[CSS-COUNTER-STYLES]]) */
ul { list-style-type: symbols(cyclic '○' '●'); }
/* Sets all unordered list items to alternate between empty and
filled circles for their markers. */
ul { list-style-type: none; }
/* Suppresses the marker entirely, unless list-style-image is specified
with a valid image. */
</pre>
</div>
<!--
██ ██████ ████████ ███████ ██████ ████ ████████ ████ ███████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██
██ ███████ ██████ ███████ ████████ ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███
████████ ██████ ██ ███████ ██████ ████ ██ ████ ███████ ██ ██
-->
<h3 id='list-style-position-property'>
Positioning Markers: The 'list-style-position' property</h3>
<pre class="propdef">
Name: list-style-position
Value: inside | outside
Initial: outside
Applies to: <a>list items</a>
Inherited: yes
Percentages: n/a
Computed value: keyword, but see prose
Animation type: discrete
</pre>
This property dictates whether the ''::marker'' is rendered inline,
or positioned just outside of the <a>list item</a>.
The values are as follows:
<dl dfn-type=value dfn-for=list-style-position>
<dt><dfn>inside</dfn>
<dd>
No special effect.
(The ''::marker'' is an inline element at the start of the <a>list item's</a> contents.)
<dt><dfn id='list-style-position-outside'>outside</dfn>
<dd>
If the <a>list item</a> is a <a>block container</a>:
the marker box is a [=block container=]
and is placed outside the [=principal box|principal block box=];
however, the position of the list-item marker adjacent to floats is undefined.
CSS does not specify the precise location of the marker box
or its position in the painting order,
but does require that it be placed on the <a>inline-start</a> side of the box,
using the <a>writing mode</a> of the box indicated by 'marker-side'.
The marker box is fixed with respect to the principal block box's border
and does not scroll with the principal box's content.
A UA may hide the marker if the element's 'overflow' is other than ''overflow/visible''.
(This allowance may change in the future.)
The size or contents of the marker box may affect
the height of the principal block box
and/or the height of its first line box,
and in some cases may cause the creation of a new line box;
this interaction is also not defined.
Issue: This is handwavey nonsense from CSS2, and needs a real definition.
If the <a>list item</a> is an <a>inline box</a>:
this value is equivalent to ''inside''.
Issue: Alternatively, ''outside'' could lay out the marker as a previous sibling of the principal inline box.
</dl>
<div class=example>
For example:
<pre>
<style>
ul.compact { list-style: inside; }
ul { list-style: outside; }
</style>
<ul class=compact>
<li>first "inside" list item comes first</li>
<li>second "inside" list item comes first</li>
</ul>
<hr>
<ul>
<li>first "outside" list item comes first</li>
<li>second "outside" list item comes first</li>
</ul>
</pre>
The above example may be formatted as:
<pre>
* first "inside" list
item comes first
* second "inside" list
item comes second
========================
* first "outside" list
item comes first
* second "outside" list
item comes second</pre>
</div>
<!--
██ ████ ██████ ████████ ██████ ████████ ██ ██ ██ ████████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ████ ██ ██
██ ██ ██████ ██ ███████ ██████ ██ ██ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████████ ████ ██████ ██ ██████ ██ ██ ████████ ████████
-->
<h3 id='list-style-property'>
Styling Markers: the 'list-style' shorthand property</h3>
<pre class='propdef shorthand'>
Name: list-style
Value: <<'list-style-position'>> || <<'list-style-image'>> || <<'list-style-type'>>
Applies to: <a>list items</a>
</pre>
The 'list-style' property is a shorthand notation
for setting the three properties 'list-style-type', 'list-style-image', and 'list-style-position'
at the same place in the style sheet.
<div class="example">
For example:
<pre highlight=css>
ul { list-style: upper-roman inside } /* Any UL */
ul ul { list-style: circle outside } /* Any UL child of a UL */
</pre>
</div>
Using a value of <css>none</css> in the shorthand is potentially ambiguous,
as <css>none</css> is a valid value for both 'list-style-image' and 'list-style-type'.
To resolve this ambiguity,
a value of <css>none</css> in the shorthand must be applied to whichever of the two properties aren't otherwise set by the shorthand.
<div class='example'>
<pre highlight=css>
list-style: none disc;
/* Sets the image to "none" and the type to "disc". */
list-style: none url(bullet.png);
/* Sets the image to "url(bullet.png)" and the type to "none". */
list-style: none;
/* Sets both image and type to "none". */
list-style: none disc url(bullet.png);
/* Syntax error */
</pre>
</div>
Note: The <<counter-style>> values of 'list-style-type'
can also create grammatical ambiguities.
As such values are ultimately <<custom-ident>> values,
the parsing rules in [[CSS-VALUES-3]] apply.
<div class=example highlight=css>
Although authors may specify 'list-style' information directly on list item elements
(e.g., <{li}> in HTML),
they should do so with care.
Consider the following rules:
<pre>
ol.alpha li { list-style: lower-alpha; }
ul li { list-style: disc; }
</pre>
The above won't work as expected.
If you nest a <{ul}> into an <a element lt="ol">ol class=alpha</a>,
the first rule's specificity will make the <{ul}>’s list items use the lower-alpha style.
<pre>
ol.alpha > li { list-style: lower-alpha; }
ul > li { list-style: disc; }
</pre>
These work as intended.
<pre>
ol.alpha { list-style: lower-alpha; }
ul { list-style: disc; }
</pre>
These are even better,
since inheritance will transfer the 'list-style' value to the list items.
</div>
<!--
██ ██ ███ ████████ ██ ██ ████████ ████████ ██████ ████ ████████ ████████
███ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ███ ██ ██ ██ ████████ █████ ██████ ████████ ███████ ██████ ██ ██ ██ ██████
██ ██ █████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ████████ ██ ██ ██████ ████ ████████ ████████
-->
<h3 id='marker-side'>
The 'marker-side' property</h3>
<pre class='propdef'>
Name: marker-side
Value: match-self | match-parent
Initial: match-self
Applies to: <a>list items</a>
Inherited: yes
Percentages: n/a
Computed value: specified keyword
Animation type: discrete
</pre>
The 'marker-side' property specifies
whether the ''::marker'' is positioned
based on the directionality of the list item itself (i.e. its [=originating element=])
or the directionality of the list container (i.e. the [=originating element=]’s parent).
In the first case, the position of the marker can vary across items in the same list,
based on the directionality assigned to each list item individually;
in the second case they will all align on the same side,
as determined by the directionality assigned to the list as a whole.
<dl dfn-type=value dfn-for=marker-side>
<dt><dfn>match-self</dfn>
<dd>
The ''::marker'' pseudo-element is positioned
using the directionality of the ''::marker''’s [=originating element=].
<dt><dfn>match-parent</dfn>
<dd>
The ''::marker'' pseudo-element is positioned
using the directionality of the ''::marker''’s [=originating element’s=] parent element.
</dl>
<div class='example'>
By default, elements or ''::marker'' pseudo-elements
position themselves according to their list item's directionality.
However, if the list item is grouped with several other list items which may have different directionality
(for example, multiple <li>s with different "dir" attributes in an <ol> in HTML),
it is sometimes more useful to have all the markers line up on one side,
so the author can specify a single "gutter" on that side
and be assured that all the markers will lie in that gutter and be visible.
Both of the following example renderings are generated from the following HTML,
with the only difference being the value of 'marker-side' on the list:
<pre highlight=html>
<ul>
<li>english one
<li dir=rtl>OWT WERBEH
<li>english three
<li dir=rtl>RUOF WERBEH
</ul>
</pre>
<table class=data style="width: 35em;">
<thead>
<tr>
<th>''match-self''
<th>''match-parent''
<tbody>
<tr>
<td style="border-right: thin solid">
<pre>
* english one
OWT WERBEH *
* english three
RUOF WERBEH *</pre>
<td>
<pre>
* english one
* OWT WERBEH
* english three
* RUOF WERBEH</pre>
</table>
</div>
<!--
██████ ███████ ██ ██ ██ ██ ████████ ████████ ████████ ██████
██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ████████ ██████
██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██
██████ ███████ ███████ ██ ██ ██ ████████ ██ ██ ██████
-->
<h2 id='auto-numbering'>
Automatic Numbering With Counters</h2>
A <dfn export>counter</dfn> is a special numeric tracker
used, among other things, to automatically number list items in CSS.
Every element has a collection of zero or more counters,
which are inherited through the document tree in a way similar to inherited property values.
Counters have a name and creator element,
which identify the counter,
and an integer value per element.
They are created and manipulated with
the <dfn export>counter properties</dfn> 'counter-increment', 'counter-set' and 'counter-reset',
and used with the ''counter()'' and ''counters()'' [=functional notations=].
Counters are referred to in CSS syntax
using the <dfn><<counter-name>></dfn> type,
which represents their name as a <<custom-ident>>.
A <<counter-name>> name cannot match the keyword ''counter-reset/none'';
such an identifier is [=invalid=] as a <<counter-name>>.
Resolving [=counter=] values on a given element is a multi-step process:
1. Existing counters are [=inherit counters|inherited=] from previous elements.
2. New counters are [=instantiated=] ('counter-reset').
3. Counter values are incremented ('counter-increment').
4. Counter values are explicitly set ('counter-set').
5. Counter values are used (''counter()''/''counters()'').
UAs may have implementation-specific limits
on the maximum or minimum value of a counter.
If a counter reset, set, or increment
would push the value outside of that range,
the value must be clamped to that range.
<h3 id='counter-reset'>
Creating Counters: the 'counter-reset' property</h3>
<pre class="propdef">
Name: counter-reset
Value: [ <<counter-name>> <<integer>>? ]+ | none
Initial: none
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: the keyword ''counter-reset/none'' or a list, each item an identifier paired with an integer
Animation type: by computed value type
</pre>
<p class=all-media>User Agents are expected to support this property on all media, including non-visual ones.
The 'counter-reset' property [=instantiates=] new [=counters=] on an element
and sets them to the specified integer values.
Its values are defined as follows:
<dl dfn-type=value dfn-for=counter-reset>
<dt><dfn>none</dfn>
<dd>
This element does not create any new counters.
<dt><dfn><<counter-name>> <<integer>>?</dfn>
<dd>
[=Instantiates=] a counter of the given <<counter-name>>
with a starting value of the given <<integer>>,
defaulting to ''0''.
</dl>
<div class='example' highlight=css>
Note that counter properties follow the [=cascading=] rules as normal.
Thus, due to cascading, the following style sheet:
<pre>
h1 { counter-reset: section -1 }
h1 { counter-reset: imagenum 99 }
</pre>
will only reset ''imagenum''.
To reset both counters,
they have to be specified together:
<pre>H1 { counter-reset: section -1 imagenum 99 }</pre>
The same principles apply to the 'counter-set' and 'counter-increment' properties.
See [[css-cascade-4]].
</div>
If multiple instances of the same <<counter-name>> occur in the property value,
only the last one is honored.
<h3 id='increment-set'>
Manipulating Counter Values: the 'counter-increment' and 'counter-set' properties</h3>
<pre class='propdef'>
Name: counter-increment
Value: [ <<counter-name>> <<integer>>? ]+ | none
Initial: none
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: the keyword ''counter-reset/none'' or a list, each item an identifier paired with an integer
Animation type: by computed value type
</pre>
<p class=all-media>User Agents are expected to support this property on all media, including non-visual ones.
<pre class='propdef'>
Name: counter-set
Value: [ <<counter-name>> <<integer>>? ]+ | none
Initial: none
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: the keyword ''counter-reset/none'' or a list, each item an identifier paired with an integer
Animation type: by computed value type
</pre>
<p class=all-media>User Agents are expected to support this property on all media, including non-visual ones.
The 'counter-increment' and 'counter-set' properties
manipulate the value of existing [=counters=].
They only [=instantiate=] new counters
if there is no counter of the given name on the element yet.
Their values are defined as follows:
<dl dfn-type=value dfn-for="counter-set counter-increment">
<dt><dfn>none</dfn>
<dd>
This element does not alter the value of any counters.
<dt><dfn><<counter-name>> <<integer>>?</dfn>
<dd>
Sets (for 'counter-set') or increments (for 'counter-increment')
the value of the named counter on the element
to/by the specified <<integer>>.
If the <<integer>> is omitted,
it defaults to ''1'' (for 'counter-increment')
or ''0'' (for 'counter-set').
If there is not currently a counter of the given name on the element,
the element [=instantiates=] a new counter of the given name
with a starting value of ''0''
before setting or incrementing its value.
</dl>
<div class="example">
<p>This example shows a way to number chapters and sections with "Chapter 1", "1.1", "1.2", etc.
<pre highlight=css>
h1::before {
content: "Chapter " counter(chapter) ". ";
counter-increment: chapter; /* Add 1 to chapter */
counter-reset: section; /* Set section to 0 */
}
h2::before {
content: counter(chapter) "." counter(section) " ";
counter-increment: section;
}
</pre>
</div>
If multiple instances of the same <<counter-name>> occur in the property value,
they are all processed, in order.
Thus increments will compound,
but only the last set value will take effect.
<h3 id='nested-counters'>
Nested Counters and Scope</h3>
Counters are “self-nesting”;
[=instantiating=] a new counter on an element
which inherited an identically-named [=counter=]
from its parent
creates a new counter of the same name,
nested inside the existing counter.
This is important for situations like lists in HTML,
where lists can be nested inside lists to arbitrary depth:
it would be impossible to define uniquely named counters for each level.
The ''counter()'' function only retrieves the [=innermost=] counter of a given name on the element,
whereas the ''counters()'' function uses all counters of a given name that contain the element.
The <dfn lt="counter scope" local-lt="scope">scope</dfn> of a [=counter=] therefore
starts at the first element in the document that [=instantiates=] that counter
and includes the element’s descendants and its following siblings with their descendants.
However, it does not include any elements in the scope of a counter with the same name
created by a 'counter-reset' on a later sibling of the element,
allowing such explicit counter instantiations
to obscure those earlier siblings.
See [[#creating-counters]] for the exact rules governing the scope of counters and their values.
<div class="example" id='counter-nesting-example'>
The following code numbers nested list items.
The result is very similar to that of setting ''display:list-item'' and ''list-style: inside'' on the LI element:
<pre highlight=css>
ol { counter-reset: item }
li { display: block }
li::before { content: counter(item) ". "; counter-increment: item }
</pre>
In this example,
an <a element>ol</a> will create a counter,
and all children of the <a element>ol</a> will refer to that counter.
If we denote the <var>n</var><sup>th</sup> instance of the ''item'' counter by item<sub><var>n</var></sub>,
then the following HTML fragment will use the indicated counters.
<div class='ol'>
<div class='ol'><code><ol></code> item<sub>0</sub> is created, set to 0
<div class='li'><code><li></code> item<sub>0</sub> is incremented to 1</div>
<div class='li'><code><li></code> item<sub>0</sub> is incremented to 2
<div class='ol'><code><ol></code> item<sub>1</sub> is created, set to 0, nested in item<sub>0</sub>
<div class='li'><code><li></code> item<sub>1</sub> is incremented to 1</div>
<div class='li'><code><li></code> item<sub>1</sub> is incremented to 2</div>
<div class='li'><code><li></code> item<sub>1</sub> is incremented to 3
<div class='ol'><code><ol></code> item<sub>2</sub> is created, set to 0, nested in item<sub>1</sub>
<div class='li'><code><li></code> item<sub>2</sub> is incremented to 1</div>
<code></ol></code>
</div>
</div>
<div class='li'><code><li></code> item<sub>1</sub> is incremented to 4
<div class='ol'><code><ol></code> item<sub>3</sub> is created, set to 0, nested in item<sub>1</sub>
<div class='li'><code><li></code> item<sub>3</sub> is incremented to 1</div>
<code></ol></code>
</div>
</div>
<div class='li'><code><li></code> item<sub>1</sub> is incremented to 5</div>
<code></ol></code>
</div>
</div>
<div class='li'><code><li></code> item<sub>0</sub> is incremented to 3</div>
<div class='li'><code><li></code> item<sub>0</sub> is incremented to 4</div>
<code></ol></code>
</div>
<div class='ol'><code><ol></code> item<sub>4</sub> is created, set to 0
<div class='li'><code><li></code> item<sub>4</sub> is incremented to 1</div>
<div class='li'><code><li></code> item<sub>4</sub> is incremented to 2</div>
<code></ol></code>
</div>
</div>
<style>
#counter-nesting-example .ol { background: rgba(0,0,0,.1); margin: .5em 0; padding: .2em .5em; }
#counter-nesting-example .li > .ol { margin: 0 0 0 1em; }
#counter-nesting-example .li { list-style: none; margin-left: 1em;}
</style>
</div>
<h3 id="creating-counters">
Creating and Inheriting Counters</h3>
Each element or pseudo-element in a document has
a (possibly empty) set of [=counters=] in the [=scope=] of that element,
either through inheritance from another element
or through instantiation on the element directly.
These counters are represented as a <dfn>CSS counters set</dfn>,
which is a [=/set=]
whose values are each a [=tuple=] of:
a [=string=] (representing a counter’s name),
an element (representing the counter’s originating element),
and an integer (representing the counter’s value).
The latest [=counter=] of a given name in that set
represents the <dfn>innermost</dfn> counter of that name.
<h4 id="inheriting-counters">
Inheriting Counters</h4>
<div algorithm>
An element [=inherit counters|inherits=] its initial set of counters
from its preceding <em>sibling</em>,
or from its parent if it has none.
It then takes the values for those counters
from the values of the matching counters
on its preceding <em>element in [=tree order=]</em>
(which might be its parent,
its preceding sibling,
or a descendant of its previous sibling).
To <dfn>inherit counters</dfn>