Web::WEBHEX maps 150 names to hex codes: the CSS Color Module Level 4 list, plus the two Acrobat JavaScript spellings dkgray and ltgray. Any of them can be used wherever a colour string is accepted, and the lookup is case-insensitive.
Lookups
<?php
require_once __DIR__ . '/vendor/autoload.php';
$web = new \Com\Tecnick\Color\Web();
echo $web->getHexFromName('cornflowerblue'), "\n";
echo $web->getNameFromHex('#6495ed'), "\n";
echo $web->extractHexCode('#369'), "\n";
echo $web->getRgbObjFromName('cornflowerblue')->getCssColor(), "\n";
6495edff
cornflowerblue
336699ff
rgb(100,149,237)
extractHexCode() normalizes a hash: it lowercases, drops the #, and expands the three and four digit forms. getNameFromHex() is the reverse of getHexFromName() and raises for a code that is not in the table. For the closest entry rather than an exact match, see Nearest Colour.
Aliases
150 names cover 139 colours. Nine hex codes carry two or three names each: seven gray and grey spellings, plus aqua/cyan and fuchsia/magenta.
| Swatch | Hex | Names | getNameFromHex() |
|---|---|---|---|
#00ffff | aqua, cyan | aqua | |
#a9a9a9 | darkgray, darkgrey, dkgray | darkgray | |
#2f4f4f | darkslategray, darkslategrey | darkslategray | |
#696969 | dimgray, dimgrey | dimgray | |
#ff00ff | fuchsia, magenta | fuchsia | |
#808080 | gray, grey | gray | |
#d3d3d3 | lightgray, lightgrey, ltgray | lightgray | |
#778899 | lightslategray, lightslategrey | lightslategray | |
#708090 | slategray, slategrey | slategray |
// three names for one colour
foreach (['darkgray', 'darkgrey', 'dkgray'] as $name) {
printf("%-10s %s\n", $name, $web->getHexFromName($name));
}
// the reverse lookup returns the first name in table order
echo $web->getNameFromHex('#a9a9a9'), "\n";
darkgray a9a9a9ff
darkgrey a9a9a9ff
dkgray a9a9a9ff
darkgray
The reverse lookup returns whichever name comes first in the table, which is the gray spelling in every pair that differs only in that letter.
dkgray and ltgray are not CSS names. They are in the table so the Acrobat JavaScript colour names resolve through the parser. Pdf::JSCOLOR spells them dkGray and ltGray and matches case-sensitively. See PDF Output.
rebeccapurple is present. transparent is not: it is handled before the table lookup and returns null, as Notations describes.
The Table
| Swatch | Name | Hex | R | G | B | CSS | HSL |
|---|---|---|---|---|---|---|---|
aliceblue | #f0f8ff | 240 | 248 | 255 | rgb(240,248,255) | hsl(208,100%,97.0588%) | |
antiquewhite | #faebd7 | 250 | 235 | 215 | rgb(250,235,215) | hsl(34.2857,77.7778%,91.1765%) | |
aqua | #00ffff | 0 | 255 | 255 | rgb(0,255,255) | hsl(180,100%,50%) | |
aquamarine | #7fffd4 | 127 | 255 | 212 | rgb(127,255,212) | hsl(159.8438,100%,74.902%) | |
azure | #f0ffff | 240 | 255 | 255 | rgb(240,255,255) | hsl(180,100%,97.0588%) | |
beige | #f5f5dc | 245 | 245 | 220 | rgb(245,245,220) | hsl(60,55.5556%,91.1765%) | |
bisque | #ffe4c4 | 255 | 228 | 196 | rgb(255,228,196) | hsl(32.5424,100%,88.4314%) | |
black | #000000 | 0 | 0 | 0 | rgb(0,0,0) | hsl(0,0%,0%) | |
blanchedalmond | #ffebcd | 255 | 235 | 205 | rgb(255,235,205) | hsl(36,100%,90.1961%) | |
blue | #0000ff | 0 | 0 | 255 | rgb(0,0,255) | hsl(240,100%,50%) | |
blueviolet | #8a2be2 | 138 | 43 | 226 | rgb(138,43,226) | hsl(271.1475,75.9336%,52.7451%) | |
brown | #a52a2a | 165 | 42 | 42 | rgb(165,42,42) | hsl(0,59.4203%,40.5882%) | |
burlywood | #deb887 | 222 | 184 | 135 | rgb(222,184,135) | hsl(33.7931,56.8627%,70%) | |
cadetblue | #5f9ea0 | 95 | 158 | 160 | rgb(95,158,160) | hsl(181.8462,25.4902%,50%) | |
chartreuse | #7fff00 | 127 | 255 | 0 | rgb(127,255,0) | hsl(90.1176,100%,50%) | |
chocolate | #d2691e | 210 | 105 | 30 | rgb(210,105,30) | hsl(25,75%,47.0588%) | |
coral | #ff7f50 | 255 | 127 | 80 | rgb(255,127,80) | hsl(16.1143,100%,65.6863%) | |
cornflowerblue | #6495ed | 100 | 149 | 237 | rgb(100,149,237) | hsl(218.5401,79.1908%,66.0784%) | |
cornsilk | #fff8dc | 255 | 248 | 220 | rgb(255,248,220) | hsl(48,100%,93.1373%) | |
crimson | #dc143c | 220 | 20 | 60 | rgb(220,20,60) | hsl(348,83.3333%,47.0588%) | |
cyan | #00ffff | 0 | 255 | 255 | rgb(0,255,255) | hsl(180,100%,50%) | |
darkblue | #00008b | 0 | 0 | 139 | rgb(0,0,139) | hsl(240,100%,27.2549%) | |
darkcyan | #008b8b | 0 | 139 | 139 | rgb(0,139,139) | hsl(180,100%,27.2549%) | |
darkgoldenrod | #b8860b | 184 | 134 | 11 | rgb(184,134,11) | hsl(42.659,88.7179%,38.2353%) | |
darkgray | #a9a9a9 | 169 | 169 | 169 | rgb(169,169,169) | hsl(0,0%,66.2745%) | |
darkgrey | #a9a9a9 | 169 | 169 | 169 | rgb(169,169,169) | hsl(0,0%,66.2745%) | |
dkgray | #a9a9a9 | 169 | 169 | 169 | rgb(169,169,169) | hsl(0,0%,66.2745%) | |
darkgreen | #006400 | 0 | 100 | 0 | rgb(0,100,0) | hsl(120,100%,19.6078%) | |
darkkhaki | #bdb76b | 189 | 183 | 107 | rgb(189,183,107) | hsl(55.6098,38.3178%,58.0392%) | |
darkmagenta | #8b008b | 139 | 0 | 139 | rgb(139,0,139) | hsl(300,100%,27.2549%) | |
darkolivegreen | #556b2f | 85 | 107 | 47 | rgb(85,107,47) | hsl(82,38.961%,30.1961%) | |
darkorange | #ff8c00 | 255 | 140 | 0 | rgb(255,140,0) | hsl(32.9412,100%,50%) | |
darkorchid | #9932cc | 153 | 50 | 204 | rgb(153,50,204) | hsl(280.1299,60.6299%,49.8039%) | |
darkred | #8b0000 | 139 | 0 | 0 | rgb(139,0,0) | hsl(0,100%,27.2549%) | |
darksalmon | #e9967a | 233 | 150 | 122 | rgb(233,150,122) | hsl(15.1351,71.6129%,69.6078%) | |
darkseagreen | #8fbc8f | 143 | 188 | 143 | rgb(143,188,143) | hsl(120,25.1397%,64.902%) | |
darkslateblue | #483d8b | 72 | 61 | 139 | rgb(72,61,139) | hsl(248.4615,39%,39.2157%) | |
darkslategray | #2f4f4f | 47 | 79 | 79 | rgb(47,79,79) | hsl(180,25.3968%,24.7059%) | |
darkslategrey | #2f4f4f | 47 | 79 | 79 | rgb(47,79,79) | hsl(180,25.3968%,24.7059%) | |
darkturquoise | #00ced1 | 0 | 206 | 209 | rgb(0,206,209) | hsl(180.8612,100%,40.9804%) | |
darkviolet | #9400d3 | 148 | 0 | 211 | rgb(148,0,211) | hsl(282.0853,100%,41.3725%) | |
deeppink | #ff1493 | 255 | 20 | 147 | rgb(255,20,147) | hsl(327.5745,100%,53.9216%) | |
deepskyblue | #00bfff | 0 | 191 | 255 | rgb(0,191,255) | hsl(195.0588,100%,50%) | |
dimgray | #696969 | 105 | 105 | 105 | rgb(105,105,105) | hsl(0,0%,41.1765%) | |
dimgrey | #696969 | 105 | 105 | 105 | rgb(105,105,105) | hsl(0,0%,41.1765%) | |
dodgerblue | #1e90ff | 30 | 144 | 255 | rgb(30,144,255) | hsl(209.6,100%,55.8824%) | |
firebrick | #b22222 | 178 | 34 | 34 | rgb(178,34,34) | hsl(0,67.9245%,41.5686%) | |
floralwhite | #fffaf0 | 255 | 250 | 240 | rgb(255,250,240) | hsl(40,100%,97.0588%) | |
forestgreen | #228b22 | 34 | 139 | 34 | rgb(34,139,34) | hsl(120,60.6936%,33.9216%) | |
fuchsia | #ff00ff | 255 | 0 | 255 | rgb(255,0,255) | hsl(300,100%,50%) | |
gainsboro | #dcdcdc | 220 | 220 | 220 | rgb(220,220,220) | hsl(0,0%,86.2745%) | |
ghostwhite | #f8f8ff | 248 | 248 | 255 | rgb(248,248,255) | hsl(240,100%,98.6275%) | |
gold | #ffd700 | 255 | 215 | 0 | rgb(255,215,0) | hsl(50.5882,100%,50%) | |
goldenrod | #daa520 | 218 | 165 | 32 | rgb(218,165,32) | hsl(42.9032,74.4%,49.0196%) | |
gray | #808080 | 128 | 128 | 128 | rgb(128,128,128) | hsl(0,0%,50.1961%) | |
grey | #808080 | 128 | 128 | 128 | rgb(128,128,128) | hsl(0,0%,50.1961%) | |
green | #008000 | 0 | 128 | 0 | rgb(0,128,0) | hsl(120,100%,25.098%) | |
greenyellow | #adff2f | 173 | 255 | 47 | rgb(173,255,47) | hsl(83.6538,100%,59.2157%) | |
honeydew | #f0fff0 | 240 | 255 | 240 | rgb(240,255,240) | hsl(120,100%,97.0588%) | |
hotpink | #ff69b4 | 255 | 105 | 180 | rgb(255,105,180) | hsl(330,100%,70.5882%) | |
indianred | #cd5c5c | 205 | 92 | 92 | rgb(205,92,92) | hsl(0,53.0516%,58.2353%) | |
indigo | #4b0082 | 75 | 0 | 130 | rgb(75,0,130) | hsl(274.6154,100%,25.4902%) | |
ivory | #fffff0 | 255 | 255 | 240 | rgb(255,255,240) | hsl(60,100%,97.0588%) | |
khaki | #f0e68c | 240 | 230 | 140 | rgb(240,230,140) | hsl(54,76.9231%,74.5098%) | |
lavender | #e6e6fa | 230 | 230 | 250 | rgb(230,230,250) | hsl(240,66.6667%,94.1176%) | |
lavenderblush | #fff0f5 | 255 | 240 | 245 | rgb(255,240,245) | hsl(340,100%,97.0588%) | |
lawngreen | #7cfc00 | 124 | 252 | 0 | rgb(124,252,0) | hsl(90.4762,100%,49.4118%) | |
lemonchiffon | #fffacd | 255 | 250 | 205 | rgb(255,250,205) | hsl(54,100%,90.1961%) | |
lightblue | #add8e6 | 173 | 216 | 230 | rgb(173,216,230) | hsl(194.7368,53.271%,79.0196%) | |
lightcoral | #f08080 | 240 | 128 | 128 | rgb(240,128,128) | hsl(0,78.8732%,72.1569%) | |
lightcyan | #e0ffff | 224 | 255 | 255 | rgb(224,255,255) | hsl(180,100%,93.9216%) | |
lightgoldenrodyellow | #fafad2 | 250 | 250 | 210 | rgb(250,250,210) | hsl(60,80%,90.1961%) | |
lightgray | #d3d3d3 | 211 | 211 | 211 | rgb(211,211,211) | hsl(0,0%,82.7451%) | |
lightgrey | #d3d3d3 | 211 | 211 | 211 | rgb(211,211,211) | hsl(0,0%,82.7451%) | |
ltgray | #d3d3d3 | 211 | 211 | 211 | rgb(211,211,211) | hsl(0,0%,82.7451%) | |
lightgreen | #90ee90 | 144 | 238 | 144 | rgb(144,238,144) | hsl(120,73.4375%,74.902%) | |
lightpink | #ffb6c1 | 255 | 182 | 193 | rgb(255,182,193) | hsl(350.9589,100%,85.6863%) | |
lightsalmon | #ffa07a | 255 | 160 | 122 | rgb(255,160,122) | hsl(17.1429,100%,73.9216%) | |
lightseagreen | #20b2aa | 32 | 178 | 170 | rgb(32,178,170) | hsl(176.7123,69.5238%,41.1765%) | |
lightskyblue | #87cefa | 135 | 206 | 250 | rgb(135,206,250) | hsl(202.9565,92%,75.4902%) | |
lightslategray | #778899 | 119 | 136 | 153 | rgb(119,136,153) | hsl(210,14.2857%,53.3333%) | |
lightslategrey | #778899 | 119 | 136 | 153 | rgb(119,136,153) | hsl(210,14.2857%,53.3333%) | |
lightsteelblue | #b0c4de | 176 | 196 | 222 | rgb(176,196,222) | hsl(213.913,41.0714%,78.0392%) | |
lightyellow | #ffffe0 | 255 | 255 | 224 | rgb(255,255,224) | hsl(60,100%,93.9216%) | |
lime | #00ff00 | 0 | 255 | 0 | rgb(0,255,0) | hsl(120,100%,50%) | |
limegreen | #32cd32 | 50 | 205 | 50 | rgb(50,205,50) | hsl(120,60.7843%,50%) | |
linen | #faf0e6 | 250 | 240 | 230 | rgb(250,240,230) | hsl(30,66.6667%,94.1176%) | |
magenta | #ff00ff | 255 | 0 | 255 | rgb(255,0,255) | hsl(300,100%,50%) | |
maroon | #800000 | 128 | 0 | 0 | rgb(128,0,0) | hsl(0,100%,25.098%) | |
mediumaquamarine | #66cdaa | 102 | 205 | 170 | rgb(102,205,170) | hsl(159.6117,50.7389%,60.1961%) | |
mediumblue | #0000cd | 0 | 0 | 205 | rgb(0,0,205) | hsl(240,100%,40.1961%) | |
mediumorchid | #ba55d3 | 186 | 85 | 211 | rgb(186,85,211) | hsl(288.0952,58.8785%,58.0392%) | |
mediumpurple | #9370db | 147 | 112 | 219 | rgb(147,112,219) | hsl(259.6262,59.7765%,64.902%) | |
mediumseagreen | #3cb371 | 60 | 179 | 113 | rgb(60,179,113) | hsl(146.7227,49.7908%,46.8627%) | |
mediumslateblue | #7b68ee | 123 | 104 | 238 | rgb(123,104,238) | hsl(248.5075,79.7619%,67.0588%) | |
mediumspringgreen | #00fa9a | 0 | 250 | 154 | rgb(0,250,154) | hsl(156.96,100%,49.0196%) | |
mediumturquoise | #48d1cc | 72 | 209 | 204 | rgb(72,209,204) | hsl(177.8102,59.8253%,55.098%) | |
mediumvioletred | #c71585 | 199 | 21 | 133 | rgb(199,21,133) | hsl(322.2472,80.9091%,43.1373%) | |
midnightblue | #191970 | 25 | 25 | 112 | rgb(25,25,112) | hsl(240,63.5036%,26.8627%) | |
mintcream | #f5fffa | 245 | 255 | 250 | rgb(245,255,250) | hsl(150,100%,98.0392%) | |
mistyrose | #ffe4e1 | 255 | 228 | 225 | rgb(255,228,225) | hsl(6,100%,94.1176%) | |
moccasin | #ffe4b5 | 255 | 228 | 181 | rgb(255,228,181) | hsl(38.1081,100%,85.4902%) | |
navajowhite | #ffdead | 255 | 222 | 173 | rgb(255,222,173) | hsl(35.8537,100%,83.9216%) | |
navy | #000080 | 0 | 0 | 128 | rgb(0,0,128) | hsl(240,100%,25.098%) | |
oldlace | #fdf5e6 | 253 | 245 | 230 | rgb(253,245,230) | hsl(39.1304,85.1852%,94.7059%) | |
olive | #808000 | 128 | 128 | 0 | rgb(128,128,0) | hsl(60,100%,25.098%) | |
olivedrab | #6b8e23 | 107 | 142 | 35 | rgb(107,142,35) | hsl(79.6262,60.452%,34.7059%) | |
orange | #ffa500 | 255 | 165 | 0 | rgb(255,165,0) | hsl(38.8235,100%,50%) | |
orangered | #ff4500 | 255 | 69 | 0 | rgb(255,69,0) | hsl(16.2353,100%,50%) | |
orchid | #da70d6 | 218 | 112 | 214 | rgb(218,112,214) | hsl(302.2642,58.8889%,64.7059%) | |
palegoldenrod | #eee8aa | 238 | 232 | 170 | rgb(238,232,170) | hsl(54.7059,66.6667%,80%) | |
palegreen | #98fb98 | 152 | 251 | 152 | rgb(152,251,152) | hsl(120,92.5234%,79.0196%) | |
paleturquoise | #afeeee | 175 | 238 | 238 | rgb(175,238,238) | hsl(180,64.9485%,80.9804%) | |
palevioletred | #db7093 | 219 | 112 | 147 | rgb(219,112,147) | hsl(340.3738,59.7765%,64.902%) | |
papayawhip | #ffefd5 | 255 | 239 | 213 | rgb(255,239,213) | hsl(37.1429,100%,91.7647%) | |
peachpuff | #ffdab9 | 255 | 218 | 185 | rgb(255,218,185) | hsl(28.2857,100%,86.2745%) | |
peru | #cd853f | 205 | 133 | 63 | rgb(205,133,63) | hsl(29.5775,58.6777%,52.549%) | |
pink | #ffc0cb | 255 | 192 | 203 | rgb(255,192,203) | hsl(349.5238,100%,87.6471%) | |
plum | #dda0dd | 221 | 160 | 221 | rgb(221,160,221) | hsl(300,47.2868%,74.7059%) | |
powderblue | #b0e0e6 | 176 | 224 | 230 | rgb(176,224,230) | hsl(186.6667,51.9231%,79.6078%) | |
purple | #800080 | 128 | 0 | 128 | rgb(128,0,128) | hsl(300,100%,25.098%) | |
rebeccapurple | #663399 | 102 | 51 | 153 | rgb(102,51,153) | hsl(270,50%,40%) | |
red | #ff0000 | 255 | 0 | 0 | rgb(255,0,0) | hsl(0,100%,50%) | |
rosybrown | #bc8f8f | 188 | 143 | 143 | rgb(188,143,143) | hsl(0,25.1397%,64.902%) | |
royalblue | #4169e1 | 65 | 105 | 225 | rgb(65,105,225) | hsl(225,72.7273%,56.8627%) | |
saddlebrown | #8b4513 | 139 | 69 | 19 | rgb(139,69,19) | hsl(25,75.9494%,30.9804%) | |
salmon | #fa8072 | 250 | 128 | 114 | rgb(250,128,114) | hsl(6.1765,93.1507%,71.3725%) | |
sandybrown | #f4a460 | 244 | 164 | 96 | rgb(244,164,96) | hsl(27.5676,87.0588%,66.6667%) | |
seagreen | #2e8b57 | 46 | 139 | 87 | rgb(46,139,87) | hsl(146.4516,50.2703%,36.2745%) | |
seashell | #fff5ee | 255 | 245 | 238 | rgb(255,245,238) | hsl(24.7059,100%,96.6667%) | |
sienna | #a0522d | 160 | 82 | 45 | rgb(160,82,45) | hsl(19.3043,56.0976%,40.1961%) | |
silver | #c0c0c0 | 192 | 192 | 192 | rgb(192,192,192) | hsl(0,0%,75.2941%) | |
skyblue | #87ceeb | 135 | 206 | 235 | rgb(135,206,235) | hsl(197.4,71.4286%,72.549%) | |
slateblue | #6a5acd | 106 | 90 | 205 | rgb(106,90,205) | hsl(248.3478,53.4884%,57.8431%) | |
slategray | #708090 | 112 | 128 | 144 | rgb(112,128,144) | hsl(210,12.5984%,50.1961%) | |
slategrey | #708090 | 112 | 128 | 144 | rgb(112,128,144) | hsl(210,12.5984%,50.1961%) | |
snow | #fffafa | 255 | 250 | 250 | rgb(255,250,250) | hsl(0,100%,99.0196%) | |
springgreen | #00ff7f | 0 | 255 | 127 | rgb(0,255,127) | hsl(149.8824,100%,50%) | |
steelblue | #4682b4 | 70 | 130 | 180 | rgb(70,130,180) | hsl(207.2727,44%,49.0196%) | |
tan | #d2b48c | 210 | 180 | 140 | rgb(210,180,140) | hsl(34.2857,43.75%,68.6275%) | |
teal | #008080 | 0 | 128 | 128 | rgb(0,128,128) | hsl(180,100%,25.098%) | |
thistle | #d8bfd8 | 216 | 191 | 216 | rgb(216,191,216) | hsl(300,24.2718%,79.8039%) | |
tomato | #ff6347 | 255 | 99 | 71 | rgb(255,99,71) | hsl(9.1304,100%,63.9216%) | |
turquoise | #40e0d0 | 64 | 224 | 208 | rgb(64,224,208) | hsl(174,72.0721%,56.4706%) | |
violet | #ee82ee | 238 | 130 | 238 | rgb(238,130,238) | hsl(300,76.0563%,72.1569%) | |
wheat | #f5deb3 | 245 | 222 | 179 | rgb(245,222,179) | hsl(39.0909,76.7442%,83.1373%) | |
white | #ffffff | 255 | 255 | 255 | rgb(255,255,255) | hsl(0,0%,100%) | |
whitesmoke | #f5f5f5 | 245 | 245 | 245 | rgb(245,245,245) | hsl(0,0%,96.0784%) | |
yellow | #ffff00 | 255 | 255 | 0 | rgb(255,255,0) | hsl(60,100%,50%) | |
yellowgreen | #9acd32 | 154 | 205 | 50 | rgb(154,205,50) | hsl(79.7419,60.7843%,50%) |
See Also
- tc-lib-color : the library overview.
- Notations : the other strings the parser accepts.
- Nearest Colour : finding the closest entry to an arbitrary colour.
- RGB : the model every one of these parses into.
- API reference : the generated class documentation.