The hexadecimal color syntax is a notation for describing an sRGB color using its primary color components (red, green, blue) written as hexadecimal numbers, as well as its transparency. It can be used everywhere a <color>
type is allowed.
Hexadecimal color syntax
Syntax
#RGB // The three-value syntax #RGBA // The four-value syntax #RRGGBB // The six-value syntax #RRGGBBAA // The eight-value syntax
Value
-
R
orRR
-
The red component of the color, as a case-insensitive hexadecimal number between
0
andff
(255)). If there is only one number, it is duplicated:1
means11
. -
G
orGG
-
The green component of the color, as a case-insensitive hexadecimal number between
0
andff
(255)). If there is only one number, it is duplicated:c
meanscc
. -
B
orBB
-
The blue component of the color, as a case-insensitive hexadecimal number between
0
andff
(255)). If there is only one number, it is duplicated:9
means99
. -
A
orAA
Optional -
The alpha component of the color, indicating its transparency, as a case-insensitive hexadecimal number between
0
andff
(255)). If there is only one number, it is duplicated:e
meansee
.0
represents a fully transparent color, andff
a fully opaque one.
Note: The syntax is case-insensitive #00ff00
is the same as #00FF00
.
Examples
/* Hexadecimal syntax for a fully opaque hot pink */ #f09 <div class="c1"></div> #F09 <div class="c2"></div> #ff0099 <div class="c3"></div> #FF0099 <div class="c4"></div>
div {width: 40px; height: 40px;} .c1 { background: #f09} .c2 { background: #F09} .c3 { background: #ff0099} .c4 { background: #FF0099}
Specifications
Specification |
---|
CSS Color Module Level 4 # hex-notation |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
hexadecimal_rgb |
1
|
12
|
1
|
3
|
3.5
|
1
|
≤37
|
18
|
4
|
10.1
|
1
|
1.0
|
alpha_hexadecimal_notation |
62
|
79
|
49
|
No
|
49
|
10
|
62
|
62
|
49
|
47
|
9.3
|
8.0
|
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hexadecimal_rgb