forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.src.html
More file actions
1943 lines (1774 loc) · 105 KB
/
Copy pathOverview.src.html
File metadata and controls
1943 lines (1774 loc) · 105 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Language" content="en">
<title>CSS Color Module Level 3</title>
<!--
FIXME when publishing: copy the current default.css and link to
"default.css" rather than "../default.css"
-->
<link rel="stylesheet" type="text/css" href="../default.css">
<style type="text/css">
.example pre {
background-color: #d5d5d5;
margin: 1em 1cm;
padding: 0 0.3cm;
}
pre { text-align:left }
pre.code { font-family: monospace }
table.colortable td {text-align:center }
table.colortable td.c { text-transform:uppercase }
table.colortable td:first-child, table.colortable td:first-child+td { border:1px solid black }
table.colortable th {text-align:center; background:black; color:white }
table.tprofile th.title {background:gray; color:white}
table.tprofile th { width:29%;padding:2px }
table.tprofile td { width:71%;padding:2px }
table.hslexample { background: #808080; padding:1em; margin:0; float:left; }
table.hslexample td,table.hslexample th { font-size:smaller;width:3em }
.toc,.subtoc ul,.subtoc ol { list-style-type: none }
.profile { margin: 1cm }
.editorNote { color: red; font-style: italic }
h1,h2,h3,h4,h5,h6 { clear:both }
h1 {font-size:200%}
h2 {font-size:170%}
h3 {font-size:150%}
h4 {font-size:130%}
h5 {font-size:120%}
h6 {font-size:110%}
.css::before, .css::after, .property::before, .property::after { content: none !important;}
</style>
<link rel="stylesheet" type="text/css" href="https://www.w3.org/StyleSheets/TR/W3C-[STATUS]">
<script src='https://test.csswg.org/harness/annotate.js#css-color-3_dev' type='text/javascript' defer></script>
</head>
<body class="h-entry">
<div class="head">
<!--logo-->
<h1 class="p-name">CSS Color Module Level 3</h1>
<h2 class="no-num no-toc">[LONGSTATUS] <time class="dt-updated" datetime="[CDATE]">[DATE]</time></h2>
<dl>
<dt>This version:</dt>
<!-- <dd><a class="u-url" href="https://www.w3.org/TR/[YEAR]/[STATUS]-[SHORTNAME]-[CDATE]">https://www.w3.org/TR/[YEAR]/[STATUS]-[SHORTNAME]-[CDATE]</a></dd> -->
<dd><a class="u-url" href="https://drafts.csswg.org/css3-color/">https://drafts.csswg.org/css-color-3/</a></dd>
<dt>Latest version:</dt>
<dd><a href="https://www.w3.org/TR/[SHORTNAME]">https://www.w3.org/TR/[SHORTNAME]</a></dd>
<dt>Previous version:</dt>
<dd><a rel="prev" href="https://www.w3.org/TR/2011/REC-css3-color-20110607/">https://www.w3.org/TR/2011/REC-css3-color-20110607/</a></dd>
<dt>Editor's Draft:</dt>
<dd><a href="https://drafts.csswg.org/css-color-3/" class="u-url">https://drafts.csswg.org/css-color-3/</a></dd>
<dt>Feedback:</dt>
<dd><a href="https://github.com/w3c/csswg-drafts/issues">GitHub Issues</a> are preferred for discussion of this specification.
When filing an issue, please put the text “css-color-3” in the title,
preferably like this:
“[css-color-3] <i>…summary of comment…</i>”.
All issues and comments are <a href="https://lists.w3.org/Archives/Public/public-css-archive/">archived</a>,
and there is also a <a href="https://lists.w3.org/Archives/Public/www-style/">historical archive</a>.
<dt>Editors:</dt>
<dd class="p-author h-card vcard"><a lang="tr" class="p-name fn u-url url" href="http://tantek.com/">Tantek Çelik</a>
(<span class="company p-org org h-card vcard"><a
class="p-name fn p-org org u-url url"
href="http://www.mozilla.org/">Mozilla Corporation</a></span>,
and before at <a href="http://www.microsoft.com/">Microsoft Corporation</a>)
<<a class="u-email email"
href="mailto:tantek@cs.stanford.edu">tantek@cs.stanford.edu</a>>
</dd>
<dd class="p-author h-card vcard"><span class="p-name fn">Chris Lilley</span> (<span
class="company p-org org h-card vcard"><a class="p-name fn p-org org u-url url"
href="http://www.w3.org/">W3C</a></span>) <<a class="u-email email"
href="mailto:chris@w3.org">chris@w3.org</a>>
</dd>
<dd class="p-author h-card vcard"><span class="p-name fn n"><abbr class="given-name">L.</abbr>
<span class="additional-name">David</span> <span
class="family-name">Baron</span></span> (<span class="company p-org org h-card vcard"><a
class="p-name fn p-org org u-url url"
href="http://www.mozilla.org/">Mozilla Corporation</a></span>) <<a
class="u-email email"
href="mailto:dbaron@dbaron.org">dbaron@dbaron.org</a>>
</dd>
<dt>Additional Authors:</dt>
<dd class="p-author h-card vcard"><span class="p-name fn">Steven Pemberton</span> (<span
class="company p-org org h-card vcard"><a class="p-name fn p-org org u-url url"
href="http://www.cwi.nl/">CWI</a></span>) <<a class="u-email email"
href="mailto:steven.pemberton@cwi.nl">steven.pemberton@cwi.nl</a>>
</dd>
<dd class="p-author h-card vcard"><span class="p-name fn">Brad Pettit</span> (<span class="company p-org org h-card vcard"><a class="fn org url"
href="http://www.microsoft.com/">Microsoft Corporation</a></span>)
<<a class="u-email email"
href="mailto:bradp@microsoft.com">bradp@microsoft.com</a>>
</dd>
<dt>Test Suite:</dt>
<dd><a
href="http://test.csswg.org/suites/css3-color/nightly-unstable/">http://test.csswg.org/suites/css3-color/nightly-unstable/</a></dd>
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc p-summary" id="abstract">Abstract</h2>
<p>CSS (Cascading Style Sheets) is a language for describing the rendering
of HTML and XML documents on screen, on paper, in speech, etc.
It uses color-related properties and values to color the
text, backgrounds, borders, and other parts of elements in a document.
This specification describes color values and properties for foreground
color and group opacity. These include properties and values from CSS
level 2 and new values.</p>
<h2 class="no-num no-toc" id="status">Status of This Document</h2>
<!--status-->
<p>This Candidate Recommendation is identical to the
<a href="http://www.w3.org/TR/2011/REC-css3-color-20110607">07 June 2011
W3C Recommendation</a> except that the
<a href="https://www.w3.org/Style/2011/REC-css3-color-20110607-errata.html">errata</a>
have been incorporated, as noted in the <a href="#changes">Changes section</a>.
One of these is a technical change; a <a href="https://test.csswg.org/harness/test/css-color-3_dev/single/t44-currentcolor-inherited-c/">test
for this change</a> is <a href="https://test.csswg.org/harness/results/css-color-3_dev/grouped/t44-currentcolor-inherited-c/">passed
by two implementations</a>.
This document is intended to become a W3C Edited Recommendation that will supersede the existing Recommendation.
This document will remain a Candidate Recommendation at least until 2 January 2018 in order to ensure the opportunity for wide review.
</p>
<p>A separate <a
href="http://www.w3.org/Style/CSS/Test/CSS3/Color/20081014/reports/CR-ImpReport.html">
implementation report</a> contains a test suite and shows that each test
in the test suite was passed by at least two independent
implementations.
</p>
<p>A complete <a href="#changes">list of changes</a>
to this document is available.
</p>
<nav id="toc">
<h2 class="no-num no-toc" id="contents">Table of Contents</h2>
<!--toc-->
</nav>
<hr>
<h2 id="introduction">Introduction</h2>
<p><em>This section is non-normative.</em>
<p>CSS beyond level 2 is a set of modules, divided up to allow the
specifications to develop incrementally, along with their
implementations. This specification is one of those modules.
</p>
<p>
This module describes CSS properties which allow authors to specify the foreground color and
opacity of an element.
This module also describes in detail the CSS <color> value type.
</p>
<p>It not only defines the color-related properties and values that
already exist in <a href="https://www.w3.org/TR/CSS1">CSS1</a> and <a
href="https://www.w3.org/TR/CSS2/">CSS2</a>, but also defines new
properties and values.</p>
<p>The Working Group doesn't expect that all implementations of CSS3 will implement
all properties or values. Instead, there will probably be a small number of variants of CSS3,
so-called "profiles". For example, it may be that only the profile for 32-bit color user agents
will include all of the proposed color-related properties and values.
</p>
<p>The specification is the result of the merging of relevant parts of
the following Recommendations and Working Drafts, and the addition of some new features.
</p>
<ul>
<li>HTML 4.01 [[HTML401]]</li>
<li>CSS 2.0 [[CSS2]]</li>
<li>SVG 1.0 [[SVG10]]</li>
<li>User Interface for CSS3 (16 February 2000) [[CSS3UI]]</li>
</ul>
<h2 id="dependencies">Dependencies</h2>
<p>Additional terminology is defined in the
<a href="https://www.w3.org/TR/CSS21/conform.html#defs">Definitions</a>
section of [[!CSS21]].
Examples of document source code and fragments are given in XML
[[XML10]] or HTML [[HTML401]]
syntax.
</p>
<h2 id="color">Color properties</h2>
<h3 id="foreground">Foreground color: the 'color' property</h3>
<table class="propdef">
<tbody>
<tr>
<th>Name:</th>
<td><dfn id="color0">color</dfn></td>
</tr>
<tr>
<th>Value:</th>
<td><color> | inherit</td>
</tr>
<tr>
<th>Initial:</th>
<td>depends on user agent</td>
</tr>
<tr>
<th>Applies to:</th>
<td>all elements</td>
</tr>
<tr>
<th>Inherited:</th>
<td>yes</td>
</tr>
<tr>
<th>Percentages:</th>
<td>N/A</td>
</tr>
</tr>
<tr>
<th>Computed value:</th>
<td>
<ul>
<li>The computed value for basic color keywords, RGB hex values and extended color keywords
is the equivalent triplet of numerical RGB values, e.g. <span class="example">six digit hex value or rgb(...) functional value</span>, with an alpha value of 1.
<li>The computed value of the keyword '<span class="index-inst">transparent</span>' is the quadruplet of all zero numerical RGBA values, e.g. <span class="example">rgba(0,0,0,0)</span>.
<li>For all other values, the computed value is the specified value.
</ul></td>
</tr>
</tbody>
</table>
<p>This property describes the foreground color of an element's text
content. In addition it is used to provide a potential indirect value
(<a href="#currentcolor" class="index-inst">currentColor</a>) for any <em>other</em> properties that accept color values.
If the '<span class="index-inst">currentColor</span>' keyword is set on the 'color' property itself, it is treated as ''color: inherit''.
</p>
<p>
There are different ways to specify lime green:
</p>
<div class="example"><p style="display:none">Example(s):</p>
<pre>
em { color: lime } /* color keyword */
em { color: rgb(0,255,0) } /* RGB range 0-255 */
</pre>
</div>
<dl>
<dt><dfn title="color:<color>"><var><color></var></dfn></dt>
<dd>Color units are defined in a <a href="#colorunits">following</a> section.
</dd>
</dl>
<h3 id="transparency">Transparency: the 'opacity' property</h3>
<p>
Opacity can be thought of as a postprocessing operation.
Conceptually, after the element (including its descendants) is rendered into an RGBA offscreen image,
the opacity setting specifies how to blend the offscreen rendering into
the current composite rendering.
See <a href="#alpha">simple alpha compositing</a> for details.
</p>
<table class="propdef">
<tbody>
<tr>
<th>Name:</th>
<td><dfn id="opacity">opacity</dfn></td>
</tr>
<tr>
<th>Value:</th>
<td><alphavalue> | inherit</td>
</tr>
<tr>
<th>Initial:</th>
<td>1</td>
</tr>
<tr>
<th>Applies to:</th>
<td>all elements</td>
</tr>
<tr>
<th>Inherited:</th>
<td>no</td>
</tr>
<tr>
<th>Percentages:</th>
<td>N/A</td>
</tr>
</tr>
<tr>
<th>Computed value:</th>
<td>The same as the specified value after clipping the <alphavalue> to the range [0.0,1.0]. </td>
</tr>
</tbody>
</table>
<dl>
<dt id="alphavaluedt"><dfn class="prop-value" id="alphavalue-def"><alphavalue></dfn></dt>
<dd>Syntactically a <number>. The uniform opacity setting to be applied across an entire object.
Any values outside the range 0.0 (fully transparent) to 1.0 (fully
opaque) will be clamped to this range.
If the object has children,
then the effect is as if the children
were blended against the current background using a mask where the
value of each pixel of the mask is <alphavalue>.
For SVG, ‘has children’ is equivalent to being a
container element [[SVG11]].
</dd>
</dl>
<p>Since an element with opacity less than 1 is composited from a
single offscreen image, content outside of it cannot be layered
in z-order between pieces of content inside of it. For the same
reason, implementations must create a new stacking context for
any element with opacity less than 1. If an element with
opacity less than 1 is not positioned, then it is painted on the
same layer, within its parent stacking context,
as positioned elements with stack level 0. If an
element with opacity less than 1 is positioned, the 'z-index'
property applies as described in [[!CSS21]], except that
if the used value is ''auto'' then the element behaves exactly as
if it were ''0''. See <a
href="https://www.w3.org/TR/CSS21/visuren.html#layers">section
9.9</a> and <a
href="https://www.w3.org/TR/CSS21/zindex.html">Appendix E</a> of
[[!CSS21]] for more information on stacking contexts. The rules
in this paragraph do not apply to SVG elements, since SVG has
its own <a
href="https://www.w3.org/TR/SVG11/render.html">rendering
model</a> ([[!SVG11]], Chapter 3).</p>
<h2 id="colorunits">Color units</h2>
<p>A
<dfn class="value-def-color" id="valuea-def-color"><color></dfn>
is either a keyword or a numerical specification.
</p>
<h3 id="html4">Basic color keywords</h3>
<p>The list of basic color keywords is: aqua, black, blue, fuchsia,
gray, green, lime, maroon, navy, olive, purple, red, silver, teal,
white, and yellow. The color names are case-insensitive.</p>
<table class="colortable">
<caption><b>Color names and <span class="index-inst" id="srgbval">sRGB</span> values</b><br></caption>
<tr><th style="background:black">Named</th><th>Numeric</th><th>Color name</th><th>Hex rgb</th><th>Decimal</th></tr>
<tr><td class="c" style="background:black"> </td><td class="c" style="background:#000000"> </td><td><dfn>black</dfn></td><td class="c" style="background:silver">#000000</td><td class="c" style="background:silver">0,0,0</td></tr>
<tr><td class="c" style="background:silver"> </td><td class="c" style="background:#C0C0C0"> </td><td><dfn>silver</dfn></td><td class="c" style="background:silver">#C0C0C0</td><td class="c" style="background:silver">192,192,192</td></tr>
<tr><td class="c" style="background:gray"> </td><td class="c" style="background:#808080"> </td><td><dfn>gray</dfn></td><td class="c" style="background:silver">#808080</td><td class="c" style="background:silver">128,128,128</td></tr>
<tr><td class="c" style="background:white"> </td><td class="c" style="background:#FFFFFF"> </td><td><dfn>white</dfn></td><td class="c" style="background:silver">#FFFFFF</td><td class="c" style="background:silver">255,255,255</td></tr>
<tr><td class="c" style="background:maroon"> </td><td class="c" style="background:#800000"> </td><td><dfn>maroon</dfn></td><td class="c" style="background:silver">#800000</td><td class="c" style="background:silver">128,0,0</td></tr>
<tr><td class="c" style="background:red"> </td><td class="c" style="background:#FF0000"> </td><td><dfn>red</dfn></td><td class="c" style="background:silver">#FF0000</td><td class="c" style="background:silver">255,0,0</td></tr>
<tr><td class="c" style="background:purple"> </td><td class="c" style="background:#800080"> </td><td><dfn>purple</dfn></td><td class="c" style="background:silver">#800080</td><td class="c" style="background:silver">128,0,128</td></tr>
<tr><td class="c" style="background:fuchsia"> </td><td class="c" style="background:#FF00FF"> </td><td><dfn>fuchsia</dfn></td><td class="c" style="background:silver">#FF00FF</td><td class="c" style="background:silver">255,0,255</td></tr>
<tr><td class="c" style="background:green"> </td><td class="c" style="background:#008000"> </td><td><dfn>green</dfn></td><td class="c" style="background:silver">#008000</td><td class="c" style="background:silver">0,128,0</td></tr>
<tr><td class="c" style="background:lime"> </td><td class="c" style="background:#00FF00"> </td><td><dfn>lime</dfn></td><td class="c" style="background:silver">#00FF00</td><td class="c" style="background:silver">0,255,0</td></tr>
<tr><td class="c" style="background:olive"> </td><td class="c" style="background:#808000"> </td><td><dfn>olive</dfn></td><td class="c" style="background:silver">#808000</td><td class="c" style="background:silver">128,128,0</td></tr>
<tr><td class="c" style="background:yellow"> </td><td class="c" style="background:#FFFF00"> </td><td><dfn>yellow</dfn></td><td class="c" style="background:silver">#FFFF00</td><td class="c" style="background:silver">255,255,0</td></tr>
<tr><td class="c" style="background:navy"> </td><td class="c" style="background:#000080"> </td><td><dfn>navy</dfn></td><td class="c" style="background:silver">#000080</td><td class="c" style="background:silver">0,0,128</td></tr>
<tr><td class="c" style="background:blue"> </td><td class="c" style="background:#0000FF"> </td><td><dfn>blue</dfn></td><td class="c" style="background:silver">#0000FF</td><td class="c" style="background:silver">0,0,255</td></tr>
<tr><td class="c" style="background:teal"> </td><td class="c" style="background:#008080"> </td><td><dfn>teal</dfn></td><td class="c" style="background:silver">#008080</td><td class="c" style="background:silver">0,128,128</td></tr>
<tr><td class="c" style="background:aqua"> </td><td class="c" style="background:#00FFFF"> </td><td><dfn>aqua</dfn></td><td class="c" style="background:silver">#00FFFF</td><td class="c" style="background:silver">0,255,255</td></tr>
</table>
<div class="example"><p style="display:none">Example(s):</p>
<pre>
body {color: black; background: white }
h1 { color: maroon }
h2 { color: olive }
</pre>
</div>
<h3 id="numerical">Numerical color values</h3>
<h4 id="rgb-color">RGB color values</h4>
<p>The <span class="index-def" title="rgb()" id="rgb-def">RGB color model</span> is used in numerical color specifications. These examples all specify the same color:</p>
<div class="example"><p style="display:none">Example(s):</p>
<pre>
em { color: #f00 } /* #rgb */
em { color: #ff0000 } /* #rrggbb */
em { color: rgb(255,0,0) }
em { color: rgb(100%, 0%, 0%) }
</pre>
</div>
<p> The format of an RGB value in hexadecimal notation is a '#'
immediately followed by either three or six hexadecimal
characters. The three-digit RGB notation (<span class="index-def">#rgb</span>) is converted into
six-digit form (<span class="index-def">#rrggbb</span>) by replicating digits, not by adding
zeros. For example, #fb0 expands to #ffbb00. This ensures that
white (#ffffff) can be specified with the short notation (#fff) and
removes any dependencies on the color depth of the display.
</p>
<p> The format of an RGB value in the functional notation is 'rgb('
followed by a comma-separated list of three numerical values (either
three integer values or three percentage values) followed by ')'.
The integer value 255 corresponds to 100%, and to F or FF in the
hexadecimal notation: rgb(255,255,255) = rgb(100%,100%,100%) =
#FFF. White space characters are allowed around the numerical values.
</p>
<p>All RGB colors are specified in the <span class="index-def" id="sRGB-def">sRGB</span> color space (see
[[!SRGB]]). User agents may vary in the fidelity with which they represent these colors, but using sRGB provides an unambiguous and
objectively measurable definition of what the color should be, which can be related to international standards (see [[!COLORIMETRY]]).
</p>
<p>Values outside the device gamut should be clipped or mapped into the
gamut when the gamut is known: the red, green, and blue values must be
changed to fall within the range supported by the device. User agents
may perform higher quality mapping of colors from one gamut to another.
This specification does not define precise clipping behavior. For a
typical CRT monitor, whose device gamut is the same as sRGB, the four
rules below are equivalent: </p>
</p>
<div class="example"><p style="display:none">Example(s):</p>
<pre>
em { color: rgb(255,0,0) } /* integer range 0 - 255 */
em { color: rgb(300,0,0) } /* clipped to rgb(255,0,0) */
em { color: rgb(255,-10,0) } /* clipped to rgb(255,0,0) */
em { color: rgb(110%, 0%, 0%) } /* clipped to rgb(100%,0%,0%) */
</pre>
</div>
<p>Other devices, such as printers, have different gamuts than sRGB;
some colors outside the 0..255 sRGB range will be representable
(inside the device gamut), while other colors inside the 0..255 sRGB
range will be outside the device gamut and will thus be mapped.
</p>
<h4 id="rgba-color">RGBA color values</h4>
<p>The <span class="index-def" title="rgba()" id="rgba-def">RGB color model is extended</a> in this specification to include
“alpha” to allow specification of the opacity of a color.
See <a href="#alpha">simple alpha compositing</a> for details.
These examples all specify the same color:</p>
<div class="example"><p style="display:none">Example(s):</p>
<pre>
em { color: rgb(255,0,0) } /* integer range 0 - 255 */
em { color: rgba(255,0,0,1) /* the same, with explicit opacity of 1 */
em { color: rgb(100%,0%,0%) } /* float range 0.0% - 100.0% */
em { color: rgba(100%,0%,0%,1) } /* the same, with explicit opacity of 1 */
</pre>
</div>
<p>Unlike RGB values, there is no hexadecimal notation for an RGBA value.
</p>
<p> The format of an RGBA value in the functional notation is 'rgba('
followed by a comma-separated list of three numerical values (either
three integer values or three percentage values), followed by an
<a href="#alphavaluedt" class="index-inst"><alphavalue></a>, followed by ')'.
The integer value 255 corresponds to 100%, rgba(255,255,255,0.8) = rgba(100%,100%,100%,0.8).
White space characters are allowed around the numerical values.
</p>
<p>Implementations must clip the red, green, and blue components of RGBA
color values to the device gamut according to the rules for the RGB
color value composed of those components.</p>
<p>These examples specify effects that are possible with the rgba() notation:</p>
<div class="example"><p style="display:none">Example(s):</p>
<pre>
p { color: rgba(0,0,255,0.5) } /* semi-transparent solid blue */
p { color: rgba(100%, 50%, 0%, 0.1) } /* very transparent solid orange */
</pre>
</div>
<p class="note"><strong>Note.</strong> If RGBA values are not supported by a user agent,
they should be treated like unrecognized values per the CSS forward compatibility parsing rules ([[!CSS21]], Chapter 4).
RGBA values must <em>not</em> be treated as simply an RGB value with the opacity ignored.
</p>
<h4 id="transparent">''transparent'' color keyword</h4>
<p>CSS1 introduced the ''transparent'' value for the background-color property. CSS2 allowed border-color to also accept the ''transparent'' value. The
Open eBook(tm) Publication Structure 1.0.1 [[OEB101]] extended the 'color' property to also accept the ''transparent'' keyword. CSS3 extends the color value to include the ''transparent'' keyword to allow its use with all properties that accept a <color> value. This simplifies the definition of those properties in CSS3.
</p>
<dl><dt><dfn id="transparent-def">transparent</dfn></dt>
<dd>Fully transparent. This keyword can be considered a shorthand for transparent black, rgba(0,0,0,0), which is its computed value.
</dd>
</dl>
<h4 id="hsl-color">HSL color values</h4>
<p>CSS3 adds numerical <span class="index-def" title="hsl()" id="hsl-def">hue-saturation-lightness (HSL) colors</a> as a complement to numerical RGB colors. It has been observed that RGB colors have the following limitations:
</p>
<ul>
<li>RGB is hardware-oriented: it reflects the use of CRTs.</li>
<li>RGB is non-intuitive. People can learn how to use RGB, but actually
by internalizing how to translate hue, saturation and
lightness, or something similar, to RGB.
</li>
</ul>
<p>
There are several other color schemes possible.
Some advantages of HSL are that it is symmetrical to lightness and darkness
(which is not the case with HSV for example), and it is trivial to
convert HSL to RGB.
</p>
<p>
HSL colors are encoding as a triple (hue, saturation, lightness).
Hue is represented as an angle of the color circle (i.e. the rainbow
represented in a circle). This angle is so typically measured in degrees that the unit is implicit in CSS; syntactically, only a <number> is given.
By definition red=0=360, and the other colors are spread around the
circle, so green=120, blue=240, etc. As an angle, it implicitly wraps around such that -120=240 and 480=120. One way an implementation could normalize such an angle x to the range [0,360) (<em>i.e.</em> zero degrees, inclusive, to 360 degrees, exclusive) is to compute (((x mod 360) + 360) mod 360). Saturation and lightness
are represented as percentages. 100% is full saturation, and 0%
is a shade of
gray. 0% lightness is black, 100% lightness is white, and 50%
lightness is “normal”.
</p>
<p>So for instance:</p>
<div class="example"><p style="display:none">Example(s):</p>
<pre>
* { color: hsl(0, 100%, 50%) } /* red */
* { color: hsl(120, 100%, 50%) } /* lime */
* { color: hsl(120, 100%, 25%) } /* dark green */
* { color: hsl(120, 100%, 75%) } /* light green */
* { color: hsl(120, 75%, 75%) } /* pastel green, and so on */
</pre>
</div>
<p>
The advantage of HSL over RGB is that it is far more intuitive: you
can guess at the colors you want, and then tweak. It is also easier to
create sets of matching colors (by keeping the hue the same and
varying the lightness/darkness, and saturation)
</p>
<p>If saturation is less than 0%, implementations must clip it to 0%.
If the resulting value is outside the device gamut, implementations must
clip it to the device gamut. This clipping should preserve the hue when
possible, but is otherwise undefined. (In other words, the clipping is
different from applying the rules for clipping of RGB colors after
applying the algorithm below for converting HSL to RGB.)</p>
<p>
The algorithm to translate HSL to RGB is simple (here expressed in ABC [[ABC]] which was
used to generate the tables.) In these algorithms, all three
values (H, S and L) have been normalized to fractions 0..1:
</p>
<pre class="code">
HOW TO RETURN hsl.to.rgb(h, s, l):
SELECT:
l<=0.5: PUT l*(s+1) IN m2
ELSE: PUT l+s-l*s IN m2
PUT l*2-m2 IN m1
PUT hue.to.rgb(m1, m2, h+1/3) IN r
PUT hue.to.rgb(m1, m2, h ) IN g
PUT hue.to.rgb(m1, m2, h-1/3) IN b
RETURN (r, g, b)
HOW TO RETURN hue.to.rgb(m1, m2, h):
IF h<0: PUT h+1 IN h
IF h>1: PUT h-1 IN h
IF h*6<1: RETURN m1+(m2-m1)*h*6
IF h*2<1: RETURN m2
IF h*3<2: RETURN m1+(m2-m1)*(2/3-h)*6
RETURN m1
</pre>
<h5 id="hsl-examples">HSL examples</h5>
<p>
Each table below represents one hue. Twelve equally spaced colors
(i.e. at 30° intervals) have been chosen
from the color circle: red, yellow, green, cyan, blue, magenta,
with all the intermediate colors (the last is the color
between magenta and red).
</p>
<p>
The X axis of each table represents the saturation (100%, 75%, 50%, 25%, 0%).
</p>
<p>
The Y axis represents the lightness. 50% is “normal”.
</p>
<table class="hslexample">
<tr><th><th colspan=5>0° Reds
<tr><th><th colspan=5>Saturation
<tr><th><th>100%<th>75%<th>50%<th>25%<th>0%
<tr><th> 100
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<tr><th> 88
<td style="background:#FFBFBF">
<td style="background:#F7C7C7">
<td style="background:#EFCFCF">
<td style="background:#E7D7D7">
<td style="background:#DFDFDF">
<tr><th> 75
<td style="background:#FF8080">
<td style="background:#EF8F8F">
<td style="background:#DF9F9F">
<td style="background:#CFAFAF">
<td style="background:#BFBFBF">
<tr><th> 63
<td style="background:#FF4040">
<td style="background:#E75858">
<td style="background:#CF7070">
<td style="background:#B78787">
<td style="background:#9F9F9F">
<tr><th> 50
<td style="background:#FF0000">
<td style="background:#DF2020">
<td style="background:#BF4040">
<td style="background:#9F6060">
<td style="background:#808080">
<tr><th> 38
<td style="background:#BF0000">
<td style="background:#A71818">
<td style="background:#8F3030">
<td style="background:#784848">
<td style="background:#606060">
<tr><th> 25
<td style="background:#800000">
<td style="background:#701010">
<td style="background:#602020">
<td style="background:#503030">
<td style="background:#404040">
<tr><th> 13
<td style="background:#400000">
<td style="background:#380808">
<td style="background:#301010">
<td style="background:#281818">
<td style="background:#202020">
<tr><th> 0
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
</table>
<table class="hslexample">
<tr><th><th colspan=5>30° Red-Yellows (=Oranges)
<tr><th><th colspan=5>Saturation
<tr><th><th>100%<th>75%<th>50%<th>25%<th>0%
<tr><th> 100
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<tr><th> 88
<td style="background:#FFDFBF">
<td style="background:#F7DFC7">
<td style="background:#EFDFCF">
<td style="background:#E7DFD7">
<td style="background:#DFDFDF">
<tr><th> 75
<td style="background:#FFBF80">
<td style="background:#EFBF8F">
<td style="background:#DFBF9F">
<td style="background:#CFBFAF">
<td style="background:#BFBFBF">
<tr><th> 63
<td style="background:#FF9F40">
<td style="background:#E79F58">
<td style="background:#CF9F70">
<td style="background:#B79F87">
<td style="background:#9F9F9F">
<tr><th> 50
<td style="background:#FF8000">
<td style="background:#DF8020">
<td style="background:#BF8040">
<td style="background:#9F8060">
<td style="background:#808080">
<tr><th> 38
<td style="background:#BF6000">
<td style="background:#A76018">
<td style="background:#8F6030">
<td style="background:#786048">
<td style="background:#606060">
<tr><th> 25
<td style="background:#804000">
<td style="background:#704010">
<td style="background:#604020">
<td style="background:#504030">
<td style="background:#404040">
<tr><th> 13
<td style="background:#402000">
<td style="background:#382008">
<td style="background:#302010">
<td style="background:#282018">
<td style="background:#202020">
<tr><th> 0
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
</table>
<table class="hslexample">
<tr><th><th colspan=5>60° Yellows
<tr><th><th colspan=5>Saturation
<tr><th><th>100%<th>75%<th>50%<th>25%<th>0%
<tr><th> 100
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<tr><th> 88
<td style="background:#FFFFBF">
<td style="background:#F7F7C7">
<td style="background:#EFEFCF">
<td style="background:#E7E7D7">
<td style="background:#DFDFDF">
<tr><th> 75
<td style="background:#FFFF80">
<td style="background:#EFEF8F">
<td style="background:#DFDF9F">
<td style="background:#CFCFAF">
<td style="background:#BFBFBF">
<tr><th> 63
<td style="background:#FFFF40">
<td style="background:#E7E758">
<td style="background:#CFCF70">
<td style="background:#B7B787">
<td style="background:#9F9F9F">
<tr><th> 50
<td style="background:#FFFF00">
<td style="background:#DFDF20">
<td style="background:#BFBF40">
<td style="background:#9F9F60">
<td style="background:#808080">
<tr><th> 38
<td style="background:#BFBF00">
<td style="background:#A7A718">
<td style="background:#8F8F30">
<td style="background:#787848">
<td style="background:#606060">
<tr><th> 25
<td style="background:#808000">
<td style="background:#707010">
<td style="background:#606020">
<td style="background:#505030">
<td style="background:#404040">
<tr><th> 13
<td style="background:#404000">
<td style="background:#383808">
<td style="background:#303010">
<td style="background:#282818">
<td style="background:#202020">
<tr><th> 0
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
</table>
<table class="hslexample">
<tr><th><th colspan=5>90° Yellow-Greens
<tr><th><th colspan=5>Saturation
<tr><th><th>100%<th>75%<th>50%<th>25%<th>0%
<tr><th> 100
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<tr><th> 88
<td style="background:#DFFFBF">
<td style="background:#DFF7C7">
<td style="background:#DFEFCF">
<td style="background:#DFE7D7">
<td style="background:#DFDFDF">
<tr><th> 75
<td style="background:#BFFF80">
<td style="background:#BFEF8F">
<td style="background:#BFDF9F">
<td style="background:#BFCFAF">
<td style="background:#BFBFBF">
<tr><th> 63
<td style="background:#9FFF40">
<td style="background:#9FE758">
<td style="background:#9FCF70">
<td style="background:#9FB787">
<td style="background:#9F9F9F">
<tr><th> 50
<td style="background:#80FF00">
<td style="background:#80DF20">
<td style="background:#80BF40">
<td style="background:#809F60">
<td style="background:#808080">
<tr><th> 38
<td style="background:#60BF00">
<td style="background:#60A718">
<td style="background:#608F30">
<td style="background:#607848">
<td style="background:#606060">
<tr><th> 25
<td style="background:#408000">
<td style="background:#407010">
<td style="background:#406020">
<td style="background:#405030">
<td style="background:#404040">
<tr><th> 13
<td style="background:#204000">
<td style="background:#203808">
<td style="background:#203010">
<td style="background:#202818">
<td style="background:#202020">
<tr><th> 0
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
</table>
<table class="hslexample">
<tr><th><th colspan=5>120° Greens
<tr><th><th colspan=5>Saturation
<tr><th><th>100%<th>75%<th>50%<th>25%<th>0%
<tr><th> 100
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<tr><th> 88
<td style="background:#BFFFBF">
<td style="background:#C7F7C7">
<td style="background:#CFEFCF">
<td style="background:#D7E7D7">
<td style="background:#DFDFDF">
<tr><th> 75
<td style="background:#80FF80">
<td style="background:#8FEF8F">
<td style="background:#9FDF9F">
<td style="background:#AFCFAF">
<td style="background:#BFBFBF">
<tr><th> 63
<td style="background:#40FF40">
<td style="background:#58E758">
<td style="background:#70CF70">
<td style="background:#87B787">
<td style="background:#9F9F9F">
<tr><th> 50
<td style="background:#00FF00">
<td style="background:#20DF20">
<td style="background:#40BF40">
<td style="background:#609F60">
<td style="background:#808080">
<tr><th> 38
<td style="background:#00BF00">
<td style="background:#18A718">
<td style="background:#308F30">
<td style="background:#487848">
<td style="background:#606060">
<tr><th> 25
<td style="background:#008000">
<td style="background:#107010">
<td style="background:#206020">
<td style="background:#305030">
<td style="background:#404040">
<tr><th> 13
<td style="background:#004000">
<td style="background:#083808">
<td style="background:#103010">
<td style="background:#182818">
<td style="background:#202020">
<tr><th> 0
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
</table>
<table class="hslexample">
<tr><th><th colspan=5>150° Green-Cyans
<tr><th><th colspan=5>Saturation
<tr><th><th>100%<th>75%<th>50%<th>25%<th>0%
<tr><th> 100
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<tr><th> 88
<td style="background:#BFFFDF">
<td style="background:#C7F7DF">
<td style="background:#CFEFDF">
<td style="background:#D7E7DF">
<td style="background:#DFDFDF">
<tr><th> 75
<td style="background:#80FFBF">
<td style="background:#8FEFBF">
<td style="background:#9FDFBF">
<td style="background:#AFCFBF">
<td style="background:#BFBFBF">
<tr><th> 63
<td style="background:#40FF9F">
<td style="background:#58E79F">
<td style="background:#70CF9F">
<td style="background:#87B79F">
<td style="background:#9F9F9F">
<tr><th> 50
<td style="background:#00FF80">
<td style="background:#20DF80">
<td style="background:#40BF80">
<td style="background:#609F80">
<td style="background:#808080">
<tr><th> 38
<td style="background:#00BF60">
<td style="background:#18A760">
<td style="background:#308F60">
<td style="background:#487860">
<td style="background:#606060">
<tr><th> 25
<td style="background:#008040">
<td style="background:#107040">
<td style="background:#206040">
<td style="background:#305040">
<td style="background:#404040">
<tr><th> 13
<td style="background:#004020">
<td style="background:#083820">
<td style="background:#103020">
<td style="background:#182820">
<td style="background:#202020">
<tr><th> 0
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
<td style="background:#000000">
</table>
<table class="hslexample">
<tr><th><th colspan=5>180° Cyans
<tr><th><th colspan=5>Saturation
<tr><th><th>100%<th>75%<th>50%<th>25%<th>0%
<tr><th> 100
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<td style="background:#FFFFFF">
<tr><th> 88
<td style="background:#BFFFFF">
<td style="background:#C7F7F7">
<td style="background:#CFEFEF">
<td style="background:#D7E7E7">
<td style="background:#DFDFDF">
<tr><th> 75
<td style="background:#80FFFF">
<td style="background:#8FEFEF">
<td style="background:#9FDFDF">
<td style="background:#AFCFCF">
<td style="background:#BFBFBF">
<tr><th> 63
<td style="background:#40FFFF">
<td style="background:#58E7E7">
<td style="background:#70CFCF">
<td style="background:#87B7B7">
<td style="background:#9F9F9F">
<tr><th> 50