<color>
CSS
data type
represents a color in the
sRGB color space
. A
<color>
may also include an
alpha-channel
transparency value
, indicating how the color should
composite
with its background.
A
<color>
can be defined in any of the following ways:
blue
or
transparent
)
rgb()
and
rgba()
functional notations)
hsl()
and
hsla()
functional notations)
注意:
This article describes the
<color>
data type in detail. To learn more about using color in HTML, see
Applying color to HTML elements using CSS
.
<color>
data type is specified using one of the options listed below.
注意:
Although
<color>
values are precisely defined, their actual appearance may vary (sometimes significantly) from device to device. This is because most devices are not calibrated, and some browsers do not support output devices'
color profiles
.
Color keywords are case-insensitive identifiers that represent a specific color, such as
red
,
blue
,
black
,或
lightseagreen
. Although the names more or less describes their respective colors, they are essentially artificial, without a strict rationale behind the names used.
There are a few caveats to consider when using color keywords:
aqua
/
cyan
fuchsia
/
magenta
darkgray
/
darkgrey
darkslategray
/
darkslategrey
dimgray
/
dimgrey
lightgray
/
lightgrey
lightslategray
/
lightslategrey
gray
/
grey
slategray
/
slategrey
注意: The list of accepted keywords has undergone many changes during the evolution of CSS:
orange
关键词。
rebeccapurple
keyword
to honor web pioneer Eric Meyer
.
| 规范 | Keyword | RGB hex value | Live keyword |
|---|---|---|---|
| CSS Level 1 |
black
|
#000000
|
|
silver
|
#c0c0c0
|
||
gray
|
#808080
|
||
white
|
#ffffff
|
||
maroon
|
#800000
|
||
red
|
#ff0000
|
||
purple
|
#800080
|
||
fuchsia
|
#ff00ff
|
||
green
|
#008000
|
||
lime
|
#00ff00
|
||
olive
|
#808000
|
||
yellow
|
#ffff00
|
||
navy
|
#000080
|
||
blue
|
#0000ff
|
||
teal
|
#008080
|
||
aqua
|
#00ffff
|
||
| CSS Level 2 (Revision 1) |
orange
|
#ffa500
|
|
| CSS Color Module Level 3 |
aliceblue
|
#f0f8ff
|
|
antiquewhite
|
#faebd7
|
||
aquamarine
|
#7fffd4
|
||
azure
|
#f0ffff
|
||
beige
|
#f5f5dc
|
||
bisque
|
#ffe4c4
|
||
blanchedalmond
|
#ffebcd
|
||
blueviolet
|
#8a2be2
|
||
brown
|
#a52a2a
|
||
burlywood
|
#deb887
|
||
cadetblue
|
#5f9ea0
|
||
chartreuse
|
#7fff00
|
||
chocolate
|
#d2691e
|
||
coral
|
#ff7f50
|
||
cornflowerblue
|
#6495ed
|
||
cornsilk
|
#fff8dc
|
||
crimson
|
#dc143c
|
||
cyan
(synonym of
aqua
)
|
#00ffff
|
||
darkblue
|
#00008b
|
||
darkcyan
|
#008b8b
|
||
darkgoldenrod
|
#b8860b
|
||
darkgray
|
#a9a9a9
|
||
darkgreen
|
#006400
|
||
darkgrey
|
#a9a9a9
|
||
darkkhaki
|
#bdb76b
|
||
darkmagenta
|
#8b008b
|
||
darkolivegreen
|
#556b2f
|
||
darkorange
|
#ff8c00
|
||
darkorchid
|
#9932cc
|
||
darkred
|
#8b0000
|
||
darksalmon
|
#e9967a
|
||
darkseagreen
|
#8fbc8f
|
||
darkslateblue
|
#483d8b
|
||
darkslategray
|
#2f4f4f
|
||
darkslategrey
|
#2f4f4f
|
||
darkturquoise
|
#00ced1
|
||
darkviolet
|
#9400d3
|
||
deeppink
|
#ff1493
|
||
deepskyblue
|
#00bfff
|
||
dimgray
|
#696969
|
||
dimgrey
|
#696969
|
||
dodgerblue
|
#1e90ff
|
||
firebrick
|
#b22222
|
||
floralwhite
|
#fffaf0
|
||
forestgreen
|
#228b22
|
||
gainsboro
|
#dcdcdc
|
||
ghostwhite
|
#f8f8ff
|
||
gold
|
#ffd700
|
||
goldenrod
|
#daa520
|
||
greenyellow
|
#adff2f
|
||
grey
|
#808080
|
||
honeydew
|
#f0fff0
|
||
hotpink
|
#ff69b4
|
||
indianred
|
#cd5c5c
|
||
indigo
|
#4b0082
|
||
ivory
|
#fffff0
|
||
khaki
|
#f0e68c
|
||
lavender
|
#e6e6fa
|
||
lavenderblush
|
#fff0f5
|
||
lawngreen
|
#7cfc00
|
||
lemonchiffon
|
#fffacd
|
||
lightblue
|
#add8e6
|
||
lightcoral
|
#f08080
|
||
lightcyan
|
#e0ffff
|
||
lightgoldenrodyellow
|
#fafad2
|
||
lightgray
|
#d3d3d3
|
||
lightgreen
|
#90ee90
|
||
lightgrey
|
#d3d3d3
|
||
lightpink
|
#ffb6c1
|
||
lightsalmon
|
#ffa07a
|
||
lightseagreen
|
#20b2aa
|
||
lightskyblue
|
#87cefa
|
||
lightslategray
|
#778899
|
||
lightslategrey
|
#778899
|
||
lightsteelblue
|
#b0c4de
|
||
lightyellow
|
#ffffe0
|
||
limegreen
|
#32cd32
|
||
linen
|
#faf0e6
|
||
magenta
(synonym of
fuchsia
)
|
#ff00ff
|
||
mediumaquamarine
|
#66cdaa
|
||
mediumblue
|
#0000cd
|
||
mediumorchid
|
#ba55d3
|
||
mediumpurple
|
#9370db
|
||
mediumseagreen
|
#3cb371
|
||
mediumslateblue
|
#7b68ee
|
||
mediumspringgreen
|
#00fa9a
|
||
mediumturquoise
|
#48d1cc
|
||
mediumvioletred
|
#c71585
|
||
midnightblue
|
#191970
|
||
mintcream
|
#f5fffa
|
||
mistyrose
|
#ffe4e1
|
||
moccasin
|
#ffe4b5
|
||
navajowhite
|
#ffdead
|
||
oldlace
|
#fdf5e6
|
||
olivedrab
|
#6b8e23
|
||
orangered
|
#ff4500
|
||
orchid
|
#da70d6
|
||
palegoldenrod
|
#eee8aa
|
||
palegreen
|
#98fb98
|
||
paleturquoise
|
#afeeee
|
||
palevioletred
|
#db7093
|
||
papayawhip
|
#ffefd5
|
||
peachpuff
|
#ffdab9
|
||
peru
|
#cd853f
|
||
pink
|
#ffc0cb
|
||
plum
|
#dda0dd
|
||
powderblue
|
#b0e0e6
|
||
rosybrown
|
#bc8f8f
|
||
royalblue
|
#4169e1
|
||
saddlebrown
|
#8b4513
|
||
salmon
|
#fa8072
|
||
sandybrown
|
#f4a460
|
||
seagreen
|
#2e8b57
|
||
seashell
|
#fff5ee
|
||
sienna
|
#a0522d
|
||
skyblue
|
#87ceeb
|
||
slateblue
|
#6a5acd
|
||
slategray
|
#708090
|
||
slategrey
|
#708090
|
||
snow
|
#fffafa
|
||
springgreen
|
#00ff7f
|
||
steelblue
|
#4682b4
|
||
tan
|
#d2b48c
|
||
thistle
|
#d8bfd8
|
||
tomato
|
#ff6347
|
||
turquoise
|
#40e0d0
|
||
violet
|
#ee82ee
|
||
wheat
|
#f5deb3
|
||
whitesmoke
|
#f5f5f5
|
||
yellowgreen
|
#9acd32
|
||
| CSS Color Module Level 4 |
rebeccapurple
|
#663399
|
transparent
keyword
transparent
keyword represents a fully transparent color. This makes the background behind the colored item completely visible. Technically,
transparent
is a shortcut for
rgba(0,0,0,0)
.
Compatibility note:
To prevent unexpected behavior, such as in a
<gradient>
, the current CSS spec states that
transparent
should be calculated in the
alpha-premultiplied color space
. However, be aware that older browsers may treat it as black with an alpha value of
0
.
Historical note:
transparent
wasn't a true color in CSS Level 2 (Revision 1). It was a special keyword that could be used instead of a regular
<color>
value on two CSS properties:
background
and
border
. It was essentially added to allow developers to override an inherited solid color. With the advent of alpha channels in CSS Colors Level 3,
transparent
was redefined as a true color. It can now be used wherever a
<color>
value can be used.
currentcolor
keyword
currentcolor
keyword represents the value of an element's
color
property. This lets you use the
color
value on properties that do not receive it by default.
若
currentcolor
is used as the value of the
color
property, it instead takes its value from the inherited value of the
color
特性。
<div style="color:blue; border: 1px dashed currentcolor;"> The color of this text is blue. <div style="background:currentcolor; height:9px;"></div> This block is surrounded by a blue border. </div>
The RGB color model defines a given color according to its red, green, and blue components. An optional alpha component represents the color's transparency.
RGB colors can be expressed through both hexadecimal (prefixed with
#
) and functional (
rgb()
,
rgba()
) notations.
注意:
As of CSS Colors Level 4,
rgba()
is an alias for
rgb()
. In browsers that implement the Level 4 standard, they accept the same parameters and behave the same way.
#RRGGBB[AA]
R
(red),
G
(green),
B
(blue), and
A
(alpha) are hexadecimal characters (0–9, A–F).
A
is optional. For example,
#ff0000
相当于
#ff0000ff
.
#RGB[A]
R
(red),
G
(green),
B
(blue), and
A
(alpha) are hexadecimal characters (0–9, A–F).
A
is optional. The three-digit notation (
#RGB
) is a shorter version of the six-digit form (
#RRGGBB
). For example,
#f09
is the same color as
#ff0099
. Likewise, the four-digit RGB notation (
#RGBA
) is a shorter version of the eight-digit form (
#RRGGBBAA
). For example,
#0f38
is the same color as
#00ff3388
.
rgb[a](R, G, B[, A])
R
(red),
G
(green), and
B
(blue) can be either
<number>
s or
<percentage>
s, where the number
255
corresponds to
100%
.
A
(alpha) can be a
<number>
between
0
and
1
,或
<percentage>
, where the number
1
corresponds to
100%
(full opacity).
rgb[a](R G B[ / A])
CSS Colors Level 4 adds support for space-separated values in the functional notation.
The HSL color model defines a given color according to its hue, saturation, and lightness components. An optional alpha component represents the color's transparency.
Many designers find HSL more intuitive than RGB, since it allows hue, saturation, and lightness to each be adjusted independently. HSL can also make it easier to create a set of matching colors (such as when you want multiple shades of a single hue).
HSL colors are expressed through the functional
hsl()
and
hsla()
notations.
注意
: As of CSS Colors Level 4,
hsla()
is an alias for
hsl()
. In browsers that implement the Level 4 standard, they accept the same parameters and behave the same way.
hsl[a](H, S, L[, A])
H
(hue)
是
<angle>
of the color circle given in
deg
s,
rad
s,
grad
s, or
turn
s in
CSS Color Module Level 4
. When written as a unitless
<number>
, it is interpreted as degrees, as specified in
CSS Color Module Level 3
. By definition, red=0deg=360deg, with the other colors spread around the circle, so green=120deg, blue=240deg, etc. As an
<angle>
, it implicitly wraps around such that -120deg=240deg, 480deg=120deg, -1turn=1turn, etc.
S
(saturation) and
L
(lightness) are percentages.
100%
saturation
is completely saturated, while
0%
is completely unsaturated (gray).
100%
lightness
is white,
0%
lightness is black, and
50%
lightness is “normal.”
A
(alpha) can be a
<number>
between
0
and
1
,或
<percentage>
, where the number
1
corresponds to
100%
(full opacity).
hsl[a](H S L[ / A])
CSS Colors Level 4 adds support for space-separated values in the functional notation.
在 forced colors mode (detectable with the forced-colors media query), most colors are restricted into a user- and browser-defined palette. These system colors are exposed by the following keywords, which can be used to ensure that the rest of the page integrates well with the restricted palette. These values may also be used in other contexts, but are not widely supported by browsers.
The keywords in the following list are defined by the CSS Color Module Level 4 specification.
Note that these keywords are case insensitive , but are listed here with mixed case for readability.
Text of active links
Background of push buttons
Text of push buttons
Background of application content or documents
Text in application content or documents
Background of input fields
Text in input fields
Text that is disabled
Background of items that are selected in a control
Text of items that are selected in a control
Text of non-active, non-visited links
Text of visited links
The following keywords were defined in earlier versions of the CSS Color Module. They are now deprecated. for use on public web pages.
Active window border.
Active window caption. Should be used with
CaptionText
as foreground color.
Background color of multiple document interface.
Desktop background.
The color of the border facing the light source for 3-D elements that appear 3-D due to that layer of surrounding border.
The color of the border away from the light source for 3-D elements that appear 3-D due to that layer of surrounding border.
Text in caption, size box, and scrollbar arrow box. Should be used with the
ActiveCaption
background color.
Inactive window border.
Inactive window caption. Should be used with the
InactiveCaptionText
foreground color.
Color of text in an inactive caption. Should be used with the
InactiveCaption
background color.
Background color for tooltip controls. Should be used with the
InfoText
foreground color.
Text color for tooltip controls. Should be used with the
InfoBackground
background color.
Menu background. Should be used with the
MenuText
or
-moz-MenuBarText
foreground color.
Text in menus. Should be used with the
Menu
background color.
Background color of scroll bars.
The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.
The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Should be used with the
ButtonText
foreground color.
The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.
The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.
The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.
Window background. Should be used with the
WindowText
foreground color.
Window frame.
Text in windows. Should be used with the
Window
background color.
The border color that goes around buttons that represent the default action for a dialog box.
The background color of a button that the mouse pointer is over (which would be
ThreeDFace
or
ButtonFace
when the mouse pointer is not over it). Should be used with the
-moz-ButtonHoverText
foreground color.
The text color of a button that the mouse pointer is over (which would be ButtonText when the mouse pointer is not over it). Should be used with the
-moz-ButtonHoverFace background
color.
Background color for selected item in a tree widget. Should be used with the
-moz-CellHighlightText
foreground color. See also
-moz-html-CellHighlight
.
Text color for a selected item in a tree. Should be used with the
-moz-CellHighlight background
color. See also
-moz-html-CellHighlightText
.
Background color for combo-boxes. Should be used with the
-moz-ComboboxText
foreground color. In versions prior to 1.9.2, use
-moz-Field
代替。
Text color for combo-boxes. Should be used with the
-moz-Combobox
background color. In versions prior to 1.9.2, use
-moz-FieldText
代替。
Background color for dialog boxes. Should be used with the
-moz-DialogText
foreground color.
Text color for dialog boxes. Should be used with the
-moz-Dialog
background color.
Background color for even-numbered rows in a tree. Should be used with the
-moz-FieldText
foreground color. In Gecko versions prior to 1.9, use
-moz-Field
。另请参阅
-moz-OddTreeRow
.
Background color for highlighted item in HTML
<select>
s. Should be used with the
-moz-html-CellHighlightText
foreground color. Prior to Gecko 1.9, use
-moz-CellHighlight
.
Text color for highlighted items in HTML
<select>
s. Should be used with the
-moz-html-CellHighlight
background color. Prior to Gecko 1.9, use
-moz-CellHighlightText
.
Background color for hovered menu items. Often similar to
Highlight
. Should be used with the
-moz-MenuHoverText
or
-moz-MenuBarHoverText
foreground color.
Text color for hovered menu items. Often similar to
HighlightText
. Should be used with the
-moz-MenuHover
background color.
Text color in menu bars. Often similar to
MenuText
. Should be used on top of
Menu
background.
Color for hovered text in menu bars. Often similar to
-moz-MenuHoverText
. Should be used on top of
-moz-MenuHover
background.
Default platform hyperlink color.
Background color for odd-numbered rows in a tree. Should be used with the
-moz-FieldText
foreground color. In Gecko versions prior to 1.9, use
-moz-Field
。另请参阅
-moz-EvenTreeRow
.
Should be used for text in objects with
.
-moz-appearance
: -moz-win-communications-toolbox;
Should be used for text in objects with
.
-moz-appearance
: -moz-win-media-toolbox
Used to access the Windows 10 custom accent color that you can set on the start menu, taskbar, title bars, etc.
Used to access the color of text placed over the Windows 10 custom accent color in the start menu, taskbar, title bars, etc.
User's preference for text color of active links. Should be used with the default document background color.
User's preference for the document background color.
User's preference for the text color.
User's preference for the text color of unvisited links. Should be used with the default document background color.
User's preference for the text color of visited links. Should be used with the default document background color.
In animations and
gradients
,
<color>
values are interpolated on each of their red, green, and blue components. Each component is interpolated as a real, floating-point number. Note that interpolation of colors happens in the
alpha-premultiplied sRGBA color space
to prevent unexpected gray colors from appearing. In animations, the interpolation's speed is determined by the
timing function
.
Some people have difficulty distinguishing colors. The WCAG 2.0 recommendation strongly advises against using color as the only means of conveying a specific message, action, or result. See Color and color contrast 了解更多信息。
In this example we provide a
<div>
and a text input. Entering a valid color into the input causes the
<div>
to adopt that color, allowing you to test our color values.
<div></div> <hr> <label for="color">Enter a valid color value:</label> <input type="text" id="color">
div {
width: 100%;
height: 200px;
}
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');
function validTextColor(stringToTest) {
if (stringToTest === "") { return false; }
if (stringToTest === "inherit") { return false; }
if (stringToTest === "transparent") { return false; }
const image = document.createElement("img");
image.style.color = "rgb(0, 0, 0)";
image.style.color = stringToTest;
if (image.style.color !== "rgb(0, 0, 0)") { return true; }
image.style.color = "rgb(255, 255, 255)";
image.style.color = stringToTest;
return image.style.color !== "rgb(255, 255, 255)";
}
inputElem.addEventListener('change', () => {
if(validTextColor(inputElem.value)) {
divElem.style.backgroundColor = inputElem.value;
divElem.textContent = '';
} else {
divElem.style.backgroundColor = 'white';
divElem.textContent = 'Invalid color value';
}
});
This example shows the many ways in which a single color can be created with the various RGB color syntaxes.
/* These syntax variations all specify the same color: a fully opaque hot pink. */ /* Hexadecimal syntax */ #f09 #F09 #ff0099 #FF0099 /* Functional syntax */ rgb(255,0,153) rgb(255, 0, 153) rgb(255, 0, 153.0) rgb(100%,0%,60%) rgb(100%, 0%, 60%) rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */ rgb(255 0 153) /* Hexadecimal syntax with alpha value */ #f09f #F09F #ff0099ff #FF0099FF /* Functional syntax with alpha value */ rgb(255, 0, 153, 1) rgb(255, 0, 153, 100%) /* Whitespace syntax */ rgb(255 0 153 / 1) rgb(255 0 153 / 100%) /* Functional syntax with floats value */ rgb(255, 0, 153.6, 1) rgb(1e2, .5e1, .5e0, +.25e2%)
/* Hexadecimal syntax */ #3a30 /* 0% opaque green */ #3A3F /* full opaque green */ #33aa3300 /* 0% opaque green */ #33AA3380 /* 50% opaque green */ /* Functional syntax */ rgba(51, 170, 51, .1) /* 10% opaque green */ rgba(51, 170, 51, .4) /* 40% opaque green */ rgba(51, 170, 51, .7) /* 70% opaque green */ rgba(51, 170, 51, 1) /* full opaque green */ /* Whitespace syntax */ rgba(51 170 51 / 0.4) /* 40% opaque green */ rgba(51 170 51 / 40%) /* 40% opaque green */ /* Functional syntax with floats value */ rgba(255, 0, 153.6, 1) rgba(1e2, .5e1, .5e0, +.25e2%)
/* These examples all specify the same color: a lavender. */ hsl(270,60%,70%) hsl(270, 60%, 70%) hsl(270 60% 70%) hsl(270deg, 60%, 70%) hsl(4.71239rad, 60%, 70%) hsl(.75turn, 60%, 70%) /* These examples all specify the same color: a lavender that is 15% opaque. */ hsl(270, 60%, 50%, .15) hsl(270, 60%, 50%, 15%) hsl(270 60% 50% / .15) hsl(270 60% 50% / 15%)
| Notation | 描述 | Live |
|---|---|---|
hsl(0, 100%, 50%)
|
red | |
hsl(30, 100%, 50%)
|
orange | |
hsl(60, 100%, 50%)
|
yellow | |
hsl(90, 100%, 50%)
|
lime green | |
hsl(120, 100%, 50%)
|
green | |
hsl(150, 100%, 50%)
|
blue-green | |
hsl(180, 100%, 50%)
|
cyan | |
hsl(210, 100%, 50%)
|
sky blue | |
hsl(240, 100%, 50%)
|
blue | |
hsl(270, 100%, 50%)
|
purple | |
hsl(300, 100%, 50%)
|
magenta | |
hsl(330, 100%, 50%)
|
pink | |
hsl(360, 100%, 50%)
|
red |
| Notation | 描述 | Live |
|---|---|---|
hsl(120, 100%, 0%)
|
black | |
hsl(120, 100%, 20%)
|
||
hsl(120, 100%, 40%)
|
||
hsl(120, 100%, 60%)
|
||
hsl(120, 100%, 80%)
|
||
hsl(120, 100%, 100%)
|
white |
| Notation | 描述 | Live |
|---|---|---|
hsl(120, 100%, 50%)
|
green | |
hsl(120, 80%, 50%)
|
||
hsl(120, 60%, 50%)
|
||
hsl(120, 40%, 50%)
|
||
hsl(120, 20%, 50%)
|
||
hsl(120, 0%, 50%)
|
gray |
hsla(240, 100%, 50%, .05) /* 5% opaque blue */ hsla(240, 100%, 50%, .4) /* 40% opaque blue */ hsla(240, 100%, 50%, .7) /* 70% opaque blue */ hsla(240, 100%, 50%, 1) /* full opaque blue */ /* Whitespace syntax */ hsla(240 100% 50% / .05) /* 5% opaque blue */ /* Percentage value for alpha */ hsla(240 100% 50% / 5%) /* 5% opaque blue */
| 规范 | 状态 | 注释 |
|---|---|---|
| CSS Color Module Level 4 | 工作草案 |
添加
rebeccapurple
, four- (
#RGBA
) and eight-digit (
#RRGGBBAA
) hexadecimal notations,
rgba()
and
hsla()
as aliases of
rgb()
and
hsl()
(both with identical parameter syntax), space-separated function parameters as an alternative to commas, percentages for alpha values, and angles for the hue component in
hsl()
colors.
|
|
CSS Color Module Level 3
The definition of '<color>' in that specification. |
推荐 |
Deprecates system colors. Adds SVG colors and
rgba()
,
hsl()
,和
hsla()
functional notations.
|
|
CSS Level 2 (Revision 1)
The definition of '<color>' in that specification. |
推荐 |
添加
orange
keyword and system colors.
|
|
CSS Level 1
The definition of '<color>' in that specification. |
推荐 | Initial definition. Includes 16 basic color keywords. |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| <color> | Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 3 | Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 1 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
Alpha color values (
rgba()
,
hsla()
)
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 3 | IE 完整支持 9 | Opera 完整支持 10 | Safari 完整支持 3.1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 2 | Samsung Internet Android 完整支持 1.0 |
RGBA hexadecimal notation (
#RRGGBBAA
,
#RGBA
)
|
Chrome
完整支持
62
|
Edge 完整支持 79 | Firefox 完整支持 49 | IE 不支持 No |
Opera
完整支持
49
|
Safari 完整支持 9.1 | WebView Android 完整支持 62 |
Chrome Android
完整支持
62
|
Firefox Android 完整支持 49 |
Opera Android
完整支持
47
|
Safari iOS 完整支持 9.3 | Samsung Internet Android 完整支持 8.0 |
currentcolor
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1.5 | IE 完整支持 9 | Opera 完整支持 9.5 | Safari 完整支持 4 | WebView Android 完整支持 37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 14 | Safari iOS 完整支持 3.2 | Samsung Internet Android 完整支持 1.0 |
Allow floats in
rgb()
and
rgba()
|
Chrome 完整支持 66 | Edge 完整支持 79 | Firefox 完整支持 52 | IE 不支持 No | Opera 完整支持 53 | Safari 完整支持 12.1 | WebView Android 完整支持 66 | Chrome Android 完整支持 66 | Firefox Android 完整支持 52 | Opera Android 完整支持 47 | Safari iOS 完整支持 12.2 | Samsung Internet Android 完整支持 9.0 |
HSL color values (
hsl()
)
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 9 | Opera 完整支持 9.5 | Safari 完整支持 3.1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 2 | Samsung Internet Android 完整支持 1.0 |
hsl()
can accept alpha values
|
Chrome 完整支持 65 | Edge 完整支持 79 | Firefox 完整支持 52 | IE 不支持 No | Opera 完整支持 52 | Safari 完整支持 12.1 | WebView Android 完整支持 65 | Chrome Android 完整支持 65 | Firefox Android 完整支持 52 | Opera Android 完整支持 47 | Safari iOS 完整支持 12.2 | Samsung Internet Android 完整支持 9.0 |
| Keyword color values | Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 |
IE
完整支持
3
注意事项
|
Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
rebeccapurple
|
Chrome 完整支持 38 | Edge 完整支持 12 | Firefox 完整支持 33 | IE 完整支持 11 | Opera 完整支持 25 | Safari 完整支持 9 | WebView Android 完整支持 38 | Chrome Android 完整支持 38 | Firefox Android 完整支持 33 | Opera Android 完整支持 25 | Safari iOS 完整支持 8 | Samsung Internet Android 完整支持 3.0 |
rgb()
can accept alpha values
|
Chrome 完整支持 65 | Edge 完整支持 79 | Firefox 完整支持 52 | IE 不支持 No | Opera 完整支持 52 | Safari 完整支持 12.1 | WebView Android 完整支持 65 | Chrome Android 完整支持 65 | Firefox Android 完整支持 52 | Opera Android 完整支持 47 | Safari iOS 完整支持 12.2 | Samsung Internet Android 完整支持 9.0 |
RGB functional notation (
rgb()
)
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 4 | Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
RGB hexadecimal notation (
#RRGGBB
,
#RGB
)
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 3 | Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
| Space-separated functional color notations | Chrome 完整支持 65 | Edge 完整支持 79 | Firefox 完整支持 52 | IE 不支持 No | Opera 完整支持 52 | Safari 完整支持 12.1 | WebView Android 完整支持 65 | Chrome Android 完整支持 65 | Firefox Android 完整支持 52 | Opera Android 完整支持 47 | Safari iOS 完整支持 12.2 | Samsung Internet Android 完整支持 9.0 |
transparent
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 3 | IE 完整支持 9 | Opera 完整支持 10 | Safari 完整支持 3.1 | WebView Android 完整支持 37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 2 | Samsung Internet Android 完整支持 1.0 |
完整支持
不支持
见实现注意事项。
用户必须明确启用此特征。
opacity
property lets you define transparency at the element level.
color
,
background-color
,
border-color
,
box-shadow
,
outline-color
,
text-shadow
<angle-percentage>
<angle>
<basic-shape>
<blend-mode>
<custom-ident>
<dimension>
<frequency-percentage>
<frequency>
<gradient>
<image>
<integer>
<length-percentage>
<length>
<number>
<percentage>
<ratio>
<resolution>
<shape>
<string>
<time-percentage>
<time>
<transform-function>
<url>
color
color-adjust
flex
ident
opacity
position