HTML Color Codes: Hex, RGB, HSL Values and All 148 Color Names
HTML color codes are values that tell a browser which color to display. The main formats are hex (#FF5733), RGB (rgb(255, 87, 51)), HSL (hsl(11, 100%, 60%)), and 148 predefined color names such as tomato or navy. Hex and RGB set red, green and blue intensity. HSL sets hue, saturation and lightness.
This guide gives you a complete chart of all 148 CSS color names with hex, RGB and HSL values, explains every color format in plain language, and shows working code you can copy into your own pages. Every value in this article was checked against the CSS Color Module Level 4 specification.
What Are HTML Color Codes?
HTML color codes are the values you write in HTML and CSS to set the color of text, backgrounds, borders, buttons and any other element on a web page. The name is a holdover from the early web, when colors were set with HTML attributes like bgcolor. Today the color itself is applied with CSS, but people still call these values “HTML color codes.”
Every color on a standard screen is a mix of red, green and blue light. Each channel has 256 levels (0 to 255), so a screen can show 256 × 256 × 256 = 16,777,216 colors. Each color code format is simply a different way of naming one of those colors.
The same orange, written five ways:
| Format | Code | Reads as |
| Hex | #FF5733 | Red FF, green 57, blue 33 |
| RGB | rgb(255, 87, 51) | Red 255, green 87, blue 51 |
| HSL | hsl(11, 100%, 60%) | Hue 11°, full saturation, 60% lightness |
| Hex with alpha | #FF573380 | Same orange at about 50% opacity |
| RGB with alpha | rgb(255 87 51 / 50%) | Same orange at 50% opacity |
The first three produce exactly the same solid orange in every modern browser. The last two show that same orange, made semi-transparent. Pick the format that is easiest for you to read and edit.
Quick Reference: Most Used HTML Color Codes
These 20 colors cover most everyday needs. The first 16 are the original HTML 4 basic colors, supported by every browser ever made.
| Color name | Hex | RGB | HSL |
| White | #FFFFFF | rgb(255, 255, 255) | hsl(0, 0%, 100%) |
| Black | #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) |
| Red | #FF0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) |
| Lime | #00FF00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) |
| Blue | #0000FF | rgb(0, 0, 255) | hsl(240, 100%, 50%) |
| Yellow | #FFFF00 | rgb(255, 255, 0) | hsl(60, 100%, 50%) |
| Cyan | #00FFFF | rgb(0, 255, 255) | hsl(180, 100%, 50%) |
| Magenta | #FF00FF | rgb(255, 0, 255) | hsl(300, 100%, 50%) |
| Silver | #C0C0C0 | rgb(192, 192, 192) | hsl(0, 0%, 75%) |
| Gray / Grey | #808080 | rgb(128, 128, 128) | hsl(0, 0%, 50%) |
| Maroon | #800000 | rgb(128, 0, 0) | hsl(0, 100%, 25%) |
| Olive | #808000 | rgb(128, 128, 0) | hsl(60, 100%, 25%) |
| Green | #008000 | rgb(0, 128, 0) | hsl(120, 100%, 25%) |
| Purple | #800080 | rgb(128, 0, 128) | hsl(300, 100%, 25%) |
| Teal | #008080 | rgb(0, 128, 128) | hsl(180, 100%, 25%) |
| Navy | #000080 | rgb(0, 0, 128) | hsl(240, 100%, 25%) |
| Orange | #FFA500 | rgb(255, 165, 0) | hsl(39, 100%, 50%) |
| Pink | #FFC0CB | rgb(255, 192, 203) | hsl(350, 100%, 88%) |
| Gold | #FFD700 | rgb(255, 215, 0) | hsl(51, 100%, 50%) |
| SkyBlue | #87CEEB | rgb(135, 206, 235) | hsl(197, 71%, 73%) |
Watch out: in CSS, the keyword green is a dark green (#008000). The bright, pure green is called lime (#00FF00). This catches a lot of beginners.
HTML Color Code Chart: All 148 Color Names by Family
CSS defines exactly 148 named colors, and every one is listed below with its hex, RGB and HSL value. You may see other numbers online: 147 is the older CSS3 list from before rebeccapurple was added, and 140 counts each gray/grey spelling pair once and leaves out rebeccapurple. Names are case-insensitive, so DarkBlue, darkblue and DARKBLUE all work.
Names like “Night”, “Black Cat” or “Vampire Gray” that appear on some charts online are not valid CSS. They are nicknames for hex values. If you type color: blackcat; the browser ignores it. Use the hex code instead.
Red HTML Color Codes
| Color name | Hex | RGB | HSL |
| LightSalmon | #FFA07A | rgb(255, 160, 122) | hsl(17, 100%, 74%) |
| Salmon | #FA8072 | rgb(250, 128, 114) | hsl(6, 93%, 71%) |
| DarkSalmon | #E9967A | rgb(233, 150, 122) | hsl(15, 72%, 70%) |
| LightCoral | #F08080 | rgb(240, 128, 128) | hsl(0, 79%, 72%) |
| IndianRed | #CD5C5C | rgb(205, 92, 92) | hsl(0, 53%, 58%) |
| Crimson | #DC143C | rgb(220, 20, 60) | hsl(348, 83%, 47%) |
| Red | #FF0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) |
| FireBrick | #B22222 | rgb(178, 34, 34) | hsl(0, 68%, 42%) |
| DarkRed | #8B0000 | rgb(139, 0, 0) | hsl(0, 100%, 27%) |
Pink HTML Color Codes
| Color name | Hex | RGB | HSL |
| Pink | #FFC0CB | rgb(255, 192, 203) | hsl(350, 100%, 88%) |
| LightPink | #FFB6C1 | rgb(255, 182, 193) | hsl(351, 100%, 86%) |
| HotPink | #FF69B4 | rgb(255, 105, 180) | hsl(330, 100%, 71%) |
| DeepPink | #FF1493 | rgb(255, 20, 147) | hsl(328, 100%, 54%) |
| PaleVioletRed | #DB7093 | rgb(219, 112, 147) | hsl(340, 60%, 65%) |
| MediumVioletRed | #C71585 | rgb(199, 21, 133) | hsl(322, 81%, 43%) |
Orange HTML Color Codes
| Color name | Hex | RGB | HSL |
| Orange | #FFA500 | rgb(255, 165, 0) | hsl(39, 100%, 50%) |
| DarkOrange | #FF8C00 | rgb(255, 140, 0) | hsl(33, 100%, 50%) |
| Coral | #FF7F50 | rgb(255, 127, 80) | hsl(16, 100%, 66%) |
| Tomato | #FF6347 | rgb(255, 99, 71) | hsl(9, 100%, 64%) |
| OrangeRed | #FF4500 | rgb(255, 69, 0) | hsl(16, 100%, 50%) |
Yellow HTML Color Codes
| Color name | Hex | RGB | HSL |
| Gold | #FFD700 | rgb(255, 215, 0) | hsl(51, 100%, 50%) |
| Yellow | #FFFF00 | rgb(255, 255, 0) | hsl(60, 100%, 50%) |
| LightYellow | #FFFFE0 | rgb(255, 255, 224) | hsl(60, 100%, 94%) |
| LemonChiffon | #FFFACD | rgb(255, 250, 205) | hsl(54, 100%, 90%) |
| LightGoldenRodYellow | #FAFAD2 | rgb(250, 250, 210) | hsl(60, 80%, 90%) |
| PapayaWhip | #FFEFD5 | rgb(255, 239, 213) | hsl(37, 100%, 92%) |
| Moccasin | #FFE4B5 | rgb(255, 228, 181) | hsl(38, 100%, 85%) |
| PeachPuff | #FFDAB9 | rgb(255, 218, 185) | hsl(28, 100%, 86%) |
| PaleGoldenRod | #EEE8AA | rgb(238, 232, 170) | hsl(55, 67%, 80%) |
| Khaki | #F0E68C | rgb(240, 230, 140) | hsl(54, 77%, 75%) |
| DarkKhaki | #BDB76B | rgb(189, 183, 107) | hsl(56, 38%, 58%) |
Purple HTML Color Codes
| Color name | Hex | RGB | HSL |
| Lavender | #E6E6FA | rgb(230, 230, 250) | hsl(240, 67%, 94%) |
| Thistle | #D8BFD8 | rgb(216, 191, 216) | hsl(300, 24%, 80%) |
| Plum | #DDA0DD | rgb(221, 160, 221) | hsl(300, 47%, 75%) |
| Orchid | #DA70D6 | rgb(218, 112, 214) | hsl(302, 59%, 65%) |
| Violet | #EE82EE | rgb(238, 130, 238) | hsl(300, 76%, 72%) |
| Fuchsia | #FF00FF | rgb(255, 0, 255) | hsl(300, 100%, 50%) |
| Magenta | #FF00FF | rgb(255, 0, 255) | hsl(300, 100%, 50%) |
| MediumOrchid | #BA55D3 | rgb(186, 85, 211) | hsl(288, 59%, 58%) |
| DarkOrchid | #9932CC | rgb(153, 50, 204) | hsl(280, 61%, 50%) |
| DarkViolet | #9400D3 | rgb(148, 0, 211) | hsl(282, 100%, 41%) |
| BlueViolet | #8A2BE2 | rgb(138, 43, 226) | hsl(271, 76%, 53%) |
| DarkMagenta | #8B008B | rgb(139, 0, 139) | hsl(300, 100%, 27%) |
| Purple | #800080 | rgb(128, 0, 128) | hsl(300, 100%, 25%) |
| MediumPurple | #9370DB | rgb(147, 112, 219) | hsl(260, 60%, 65%) |
| MediumSlateBlue | #7B68EE | rgb(123, 104, 238) | hsl(249, 80%, 67%) |
| SlateBlue | #6A5ACD | rgb(106, 90, 205) | hsl(248, 53%, 58%) |
| DarkSlateBlue | #483D8B | rgb(72, 61, 139) | hsl(248, 39%, 39%) |
| RebeccaPurple | #663399 | rgb(102, 51, 153) | hsl(270, 50%, 40%) |
| Indigo | #4B0082 | rgb(75, 0, 130) | hsl(275, 100%, 25%) |
Green HTML Color Codes
| Color name | Hex | RGB | HSL |
| GreenYellow | #ADFF2F | rgb(173, 255, 47) | hsl(84, 100%, 59%) |
| Chartreuse | #7FFF00 | rgb(127, 255, 0) | hsl(90, 100%, 50%) |
| LawnGreen | #7CFC00 | rgb(124, 252, 0) | hsl(90, 100%, 49%) |
| Lime | #00FF00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) |
| LimeGreen | #32CD32 | rgb(50, 205, 50) | hsl(120, 61%, 50%) |
| PaleGreen | #98FB98 | rgb(152, 251, 152) | hsl(120, 93%, 79%) |
| LightGreen | #90EE90 | rgb(144, 238, 144) | hsl(120, 73%, 75%) |
| MediumSpringGreen | #00FA9A | rgb(0, 250, 154) | hsl(157, 100%, 49%) |
| SpringGreen | #00FF7F | rgb(0, 255, 127) | hsl(150, 100%, 50%) |
| MediumSeaGreen | #3CB371 | rgb(60, 179, 113) | hsl(147, 50%, 47%) |
| SeaGreen | #2E8B57 | rgb(46, 139, 87) | hsl(146, 50%, 36%) |
| ForestGreen | #228B22 | rgb(34, 139, 34) | hsl(120, 61%, 34%) |
| Green | #008000 | rgb(0, 128, 0) | hsl(120, 100%, 25%) |
| DarkGreen | #006400 | rgb(0, 100, 0) | hsl(120, 100%, 20%) |
| YellowGreen | #9ACD32 | rgb(154, 205, 50) | hsl(80, 61%, 50%) |
| OliveDrab | #6B8E23 | rgb(107, 142, 35) | hsl(80, 60%, 35%) |
| DarkOliveGreen | #556B2F | rgb(85, 107, 47) | hsl(82, 39%, 30%) |
| MediumAquamarine | #66CDAA | rgb(102, 205, 170) | hsl(160, 51%, 60%) |
| DarkSeaGreen | #8FBC8F | rgb(143, 188, 143) | hsl(120, 25%, 65%) |
| LightSeaGreen | #20B2AA | rgb(32, 178, 170) | hsl(177, 70%, 41%) |
| DarkCyan | #008B8B | rgb(0, 139, 139) | hsl(180, 100%, 27%) |
| Teal | #008080 | rgb(0, 128, 128) | hsl(180, 100%, 25%) |
| Olive | #808000 | rgb(128, 128, 0) | hsl(60, 100%, 25%) |
Cyan HTML Color Codes
| Color name | Hex | RGB | HSL |
| Aqua | #00FFFF | rgb(0, 255, 255) | hsl(180, 100%, 50%) |
| Cyan | #00FFFF | rgb(0, 255, 255) | hsl(180, 100%, 50%) |
| LightCyan | #E0FFFF | rgb(224, 255, 255) | hsl(180, 100%, 94%) |
| PaleTurquoise | #AFEEEE | rgb(175, 238, 238) | hsl(180, 65%, 81%) |
| Aquamarine | #7FFFD4 | rgb(127, 255, 212) | hsl(160, 100%, 75%) |
| Turquoise | #40E0D0 | rgb(64, 224, 208) | hsl(174, 72%, 56%) |
| MediumTurquoise | #48D1CC | rgb(72, 209, 204) | hsl(178, 60%, 55%) |
| DarkTurquoise | #00CED1 | rgb(0, 206, 209) | hsl(181, 100%, 41%) |
Blue HTML Color Codes
| Color name | Hex | RGB | HSL |
| CadetBlue | #5F9EA0 | rgb(95, 158, 160) | hsl(182, 25%, 50%) |
| SteelBlue | #4682B4 | rgb(70, 130, 180) | hsl(207, 44%, 49%) |
| LightSteelBlue | #B0C4DE | rgb(176, 196, 222) | hsl(214, 41%, 78%) |
| LightBlue | #ADD8E6 | rgb(173, 216, 230) | hsl(195, 53%, 79%) |
| PowderBlue | #B0E0E6 | rgb(176, 224, 230) | hsl(187, 52%, 80%) |
| LightSkyBlue | #87CEFA | rgb(135, 206, 250) | hsl(203, 92%, 75%) |
| SkyBlue | #87CEEB | rgb(135, 206, 235) | hsl(197, 71%, 73%) |
| CornflowerBlue | #6495ED | rgb(100, 149, 237) | hsl(219, 79%, 66%) |
| DeepSkyBlue | #00BFFF | rgb(0, 191, 255) | hsl(195, 100%, 50%) |
| DodgerBlue | #1E90FF | rgb(30, 144, 255) | hsl(210, 100%, 56%) |
| RoyalBlue | #4169E1 | rgb(65, 105, 225) | hsl(225, 73%, 57%) |
| Blue | #0000FF | rgb(0, 0, 255) | hsl(240, 100%, 50%) |
| MediumBlue | #0000CD | rgb(0, 0, 205) | hsl(240, 100%, 40%) |
| DarkBlue | #00008B | rgb(0, 0, 139) | hsl(240, 100%, 27%) |
| Navy | #000080 | rgb(0, 0, 128) | hsl(240, 100%, 25%) |
| MidnightBlue | #191970 | rgb(25, 25, 112) | hsl(240, 64%, 27%) |
Brown HTML Color Codes
| Color name | Hex | RGB | HSL |
| Cornsilk | #FFF8DC | rgb(255, 248, 220) | hsl(48, 100%, 93%) |
| BlanchedAlmond | #FFEBCD | rgb(255, 235, 205) | hsl(36, 100%, 90%) |
| Bisque | #FFE4C4 | rgb(255, 228, 196) | hsl(33, 100%, 88%) |
| NavajoWhite | #FFDEAD | rgb(255, 222, 173) | hsl(36, 100%, 84%) |
| Wheat | #F5DEB3 | rgb(245, 222, 179) | hsl(39, 77%, 83%) |
| BurlyWood | #DEB887 | rgb(222, 184, 135) | hsl(34, 57%, 70%) |
| Tan | #D2B48C | rgb(210, 180, 140) | hsl(34, 44%, 69%) |
| RosyBrown | #BC8F8F | rgb(188, 143, 143) | hsl(0, 25%, 65%) |
| SandyBrown | #F4A460 | rgb(244, 164, 96) | hsl(28, 87%, 67%) |
| GoldenRod | #DAA520 | rgb(218, 165, 32) | hsl(43, 74%, 49%) |
| DarkGoldenRod | #B8860B | rgb(184, 134, 11) | hsl(43, 89%, 38%) |
| Peru | #CD853F | rgb(205, 133, 63) | hsl(30, 59%, 53%) |
| Chocolate | #D2691E | rgb(210, 105, 30) | hsl(25, 75%, 47%) |
| Maroon | #800000 | rgb(128, 0, 0) | hsl(0, 100%, 25%) |
| SaddleBrown | #8B4513 | rgb(139, 69, 19) | hsl(25, 76%, 31%) |
| Sienna | #A0522D | rgb(160, 82, 45) | hsl(19, 56%, 40%) |
| Brown | #A52A2A | rgb(165, 42, 42) | hsl(0, 59%, 41%) |
White HTML Color Codes
| Color name | Hex | RGB | HSL |
| White | #FFFFFF | rgb(255, 255, 255) | hsl(0, 0%, 100%) |
| Snow | #FFFAFA | rgb(255, 250, 250) | hsl(0, 100%, 99%) |
| HoneyDew | #F0FFF0 | rgb(240, 255, 240) | hsl(120, 100%, 97%) |
| MintCream | #F5FFFA | rgb(245, 255, 250) | hsl(150, 100%, 98%) |
| Azure | #F0FFFF | rgb(240, 255, 255) | hsl(180, 100%, 97%) |
| AliceBlue | #F0F8FF | rgb(240, 248, 255) | hsl(208, 100%, 97%) |
| GhostWhite | #F8F8FF | rgb(248, 248, 255) | hsl(240, 100%, 99%) |
| WhiteSmoke | #F5F5F5 | rgb(245, 245, 245) | hsl(0, 0%, 96%) |
| SeaShell | #FFF5EE | rgb(255, 245, 238) | hsl(25, 100%, 97%) |
| Beige | #F5F5DC | rgb(245, 245, 220) | hsl(60, 56%, 91%) |
| OldLace | #FDF5E6 | rgb(253, 245, 230) | hsl(39, 85%, 95%) |
| FloralWhite | #FFFAF0 | rgb(255, 250, 240) | hsl(40, 100%, 97%) |
| Ivory | #FFFFF0 | rgb(255, 255, 240) | hsl(60, 100%, 97%) |
| AntiqueWhite | #FAEBD7 | rgb(250, 235, 215) | hsl(34, 78%, 91%) |
| Linen | #FAF0E6 | rgb(250, 240, 230) | hsl(30, 67%, 94%) |
| LavenderBlush | #FFF0F5 | rgb(255, 240, 245) | hsl(340, 100%, 97%) |
| MistyRose | #FFE4E1 | rgb(255, 228, 225) | hsl(6, 100%, 94%) |
Gray and Black HTML Color Codes
| Color name | Hex | RGB | HSL |
| Gainsboro | #DCDCDC | rgb(220, 220, 220) | hsl(0, 0%, 86%) |
| LightGray / LightGrey | #D3D3D3 | rgb(211, 211, 211) | hsl(0, 0%, 83%) |
| Silver | #C0C0C0 | rgb(192, 192, 192) | hsl(0, 0%, 75%) |
| DarkGray / DarkGrey | #A9A9A9 | rgb(169, 169, 169) | hsl(0, 0%, 66%) |
| DimGray / DimGrey | #696969 | rgb(105, 105, 105) | hsl(0, 0%, 41%) |
| Gray / Grey | #808080 | rgb(128, 128, 128) | hsl(0, 0%, 50%) |
| LightSlateGray / LightSlateGrey | #778899 | rgb(119, 136, 153) | hsl(210, 14%, 53%) |
| SlateGray / SlateGrey | #708090 | rgb(112, 128, 144) | hsl(210, 13%, 50%) |
| DarkSlateGray / DarkSlateGrey | #2F4F4F | rgb(47, 79, 79) | hsl(180, 25%, 25%) |
| Black | #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) |
Notice that a few names share a value: aqua and cyan are both #00FFFF, and fuchsia and magenta are both #FF00FF. Either name works.
The 5 Ways to Write a Color in HTML and CSS
There are five color formats you will meet on the web: hex, RGB, HSL, color names, and the newer wide-gamut formats like OKLCH. All examples below use the same orange so you can compare them directly.
1. Hex Codes (#RRGGBB)
A hex code is a # followed by six hexadecimal digits. Hexadecimal counts from 0 to 9 and then A to F, so each digit has 16 possible values. Each pair of digits sets one color channel from 00 (none) to FF (full, which equals 255).
/* #RR GG BB */
color: #FF5733; /* red FF, green 57, blue 33 */Hex codes have two useful variations:
- 3-digit shorthand. When both digits in every pair are the same, you can write each pair once. #FF0000 becomes #F00, and #336699 becomes #369. A code like #FF5733 cannot be shortened, because the middle pair 57 does not repeat. Every pair must repeat for the shorthand to work.
- 8-digit hex with transparency. Add a fourth pair to set opacity (alpha). #FF573380 is the same orange at about 50% opacity, since 80 in hex is 128, roughly half of 255. There is also a 4-digit shorthand: #F008 is red at about 53% opacity.
Hex codes are not case-sensitive. #ff5733 and #FF5733 produce the same color.
2. RGB and RGBA
RGB writes the same three channels as decimal numbers from 0 to 255, which many people find easier to read than hex.
color: rgb(255, 87, 51); /* classic comma syntax */
color: rgba(255, 87, 51, 0.5); /* 50% transparent */
color: rgb(255 87 51 / 50%); /* modern syntax, same result */The alpha value runs from 0 (fully transparent) to 1 (fully solid), or from 0% to 100%. In modern CSS, rgb() and rgba() are aliases, so rgb() accepts an alpha value too. The space-separated syntax with a slash is the current standard, and all major browsers support it.
3. HSL and HSLA
HSL describes a color the way people think about it: what color it is, how vivid it is, and how light or dark it is.
- Hue: a position on the color wheel from 0 to 360 degrees. 0 is red, 120 is green, 240 is blue.
- Saturation: from 0% (gray) to 100% (full color).
- Lightness: from 0% (black) through 50% (pure color) to 100% (white).
color: hsl(11, 100%, 60%); /* our orange */
color: hsl(11, 100%, 40%); /* darker orange: only lightness changed */
color: hsl(11 100% 60% / 0.5); /* 50% transparent, modern syntax */HSL is the easiest format for building color variations. To make a hover state darker, lower the lightness. To make a muted version, lower the saturation. The hue stays the same, so the colors always match.
4. Color Names
CSS has 148 built-in color keywords, from aliceblue to yellowgreen (see the full chart above). They are quick to type and easy to read, which makes them handy for prototypes, demos and teaching.
color: tomato;
background-color: navy;
border-color: rebeccapurple;Two special keywords are worth knowing. transparent is a fully see-through color, the same as rgb(0 0 0 / 0). currentColor reuses the element’s own text color, which is useful for borders and icons that should always match the text.
The limitation of names is choice: 148 names cover a tiny slice of the 16.7 million available colors, so brand colors almost always need hex, RGB or HSL.
5. Modern Formats: HWB, LAB, LCH and OKLCH
CSS Color Module Level 4 added several newer formats. All current versions of Chrome, Edge, Firefox and Safari support them.
| Format | Example (our orange) | What it is good for |
| HWB | hwb(11 20% 0%) | Hue plus how much white and black to mix in. Very intuitive for tints and shades. |
| OKLCH | oklch(68% 0.21 34) | Lightness, chroma (intensity) and hue. Steps in lightness look even to the human eye, and it can reach the brighter colors of modern P3 displays. |
| LAB and LCH | lab(…), lch(…) | Device-independent color spaces, mostly used for color science and print-to-web matching. |
For most websites, hex or HSL is still the practical choice. OKLCH is worth learning if you build design systems or color palettes, because it produces more consistent shades than HSL.
Hex vs RGB vs HSL: Which Should You Use?
Use hex for fixed brand colors, HSL when you need variations of one color, and RGB when you work with JavaScript or need transparency in older codebases. All three describe the same 16.7 million colors, so the choice is about readability, not quality.
| Feature | Hex | RGB | HSL | Color names |
| Example | #FF5733 | rgb(255 87 51) | hsl(11 100% 60%) | tomato |
| Transparency | Yes (8-digit) | Yes (alpha value) | Yes (alpha value) | Only transparent |
| Easy to read | Low | Medium | High | Highest |
| Easy to tweak | Hard | Medium | Easy | Not possible |
| Colors available | 16.7 million | 16.7 million | 16.7 million | 148 |
| Where you usually see it | Design tools (Figma, Photoshop), brand guides | JavaScript, canvas, older CSS | Design systems, themes, hover states | Demos, prototypes, teaching |
| Best for | Copying exact colors | Programmatic color math | Building shades and tints | Quick tests |
A practical workflow many developers follow: copy the hex code from your design tool, then convert it to HSL in your stylesheet if you need lighter or darker versions of it.
How to Use Color Codes in HTML and CSS
You apply a color code through a CSS property. The four you will use most are color (text), background-color, border-color and background (for gradients). Every example below works in all modern browsers.
Change Text Color
<p style="color: #FF5733;">This text is orange.</p>Change Background Color
<div style="background-color: rgb(30 144 255); color: white; padding: 16px;">
White text on a dodger blue background.
</div>Change Border Color
<div style="border: 3px solid hsl(120, 61%, 34%);">
A forest green border.
</div>Create a Gradient
.banner {
background: linear-gradient(90deg, #FF5733, #FFD700);
}Use a Stylesheet Instead of Inline Styles
The inline style attribute is fine for quick tests. For real websites, put colors in a stylesheet so you can change them in one place.
<style>
:root {
--brand: #FF5733;
--brand-dark: hsl(11, 100%, 40%);
}
.button {
background-color: var(--brand);
color: #FFFFFF;
}
.button:hover {
background-color: var(--brand-dark);
}
</style>
<a class="button" href="#">Get started</a>The –brand lines are CSS custom properties (also called CSS variables). Define each color once and reuse it everywhere. Changing your brand color later then takes one edit instead of fifty.
What About < font color > and bgcolor?
Many school and college textbooks still teach the old HTML way of setting colors:
<!-- Old HTML 4 style. Do not use on new websites. -->
<body bgcolor="yellow">
<font color="red">Hello</font>
</body>The tag and the bgcolor attribute were removed from the HTML standard. Browsers still display them for backward compatibility, so they are fine for an exam answer, but use CSS for anything you publish. The color values themselves (names and hex codes) are exactly the same in both methods.
How to Convert Hex to RGB (and Back) by Hand
To convert a hex code to RGB, split it into three pairs and convert each pair from base 16 to base 10. You only need one rule: in hex, A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
Worked example: convert #FF5733 to RGB
- Remove the # and split the code into pairs: FF, 57, 33.
- For each pair, multiply the first digit by 16 and add the second digit.
- Red: FF = 15 × 16 + 15 = 255
- Green: 57 = 5 × 16 + 7 = 87
- Blue: 33 = 3 × 16 + 3 = 51
- Result: rgb(255, 87, 51).
Going the other way: convert rgb(30, 144, 255) to hex
- Divide each number by 16. The whole number is the first digit; the remainder is the second.
- Red: 30 ÷ 16 = 1 remainder 14 → 1E
- Green: 144 ÷ 16 = 9 remainder 0 → 90
- Blue: 255 ÷ 16 = 15 remainder 15 → FF
- Result: #1E90FF (which is the named color dodgerblue).
For everyday work you do not need to do this by hand. Every browser’s developer tools (right-click any element, choose Inspect, then click a color swatch) will convert between hex, RGB and HSL instantly. Shift-clicking the swatch in Chrome and Edge cycles through the formats.
Color Contrast and Accessibility (WCAG)
A color that looks good is not enough: text must also have enough contrast against its background for people with low vision or color blindness to read it. The Web Content Accessibility Guidelines (WCAG 2.2) set minimum contrast ratios, measured from 1:1 (no contrast) to 21:1 (black on white).
| Text type | WCAG AA (minimum) | WCAG AAA (enhanced) |
| Normal text | 4.5:1 | 7:1 |
| Large text (24px, or 18.66px bold) | 3:1 | 4.5:1 |
| Icons, buttons and form borders | 3:1 | Not defined |
Here is how some common pairings score. These ratios were calculated with the WCAG formula.
| Text color | Background | Contrast ratio | AA normal text |
| #FFFFFF (white) | #000080 (navy) | 16.01:1 | Pass |
| #000000 (black) | #FFD700 (gold) | 14.97:1 | Pass |
| #FFFFFF (white) | #767676 | 4.54:1 | Pass (just) |
| #FFFFFF (white) | #808080 (gray) | 3.95:1 | Fail |
| #FFFFFF (white) | #1E90FF (dodgerblue) | 3.24:1 | Fail |
| #FFFFFF (white) | #FF5733 (orange) | 3.15:1 | Fail |
#767676 is worth remembering: it is the lightest gray that passes AA for normal text on a white background. Bright oranges, yellows and light blues almost always fail with white text, even though they look readable on a good monitor.
To check your own colors, use the WebAIM Contrast Checker or the contrast readout in Chrome DevTools, which appears when you click a text color swatch. And never use color alone to carry meaning: add an icon or text label to error messages and status indicators, since about 1 in 12 men has some form of color vision deficiency.
Common Mistakes with HTML Color Codes
- Forgetting the #. color: FF5733; does nothing. Hex codes need the hash: color: #FF5733;.
- Using names that are not real CSS colors. “Night”, “Charcoal” or “Baby Blue” appear on many charts online, but browsers ignore them. Only the 148 names in the chart above work.
- Expecting green to be bright green. It is #008000. Use lime for pure #00FF00.
- Wrong number of hex digits. Valid lengths are 3, 4, 6 or 8 digits. A 5-digit code like #FF573 is invalid and is ignored.
- Mixing up opacity and color alpha. opacity: 0.5 fades the whole element, including its text and children. background-color: rgb(255 87 51 / 50%) fades only the background.
- Picking colors only by eye. Check contrast with a tool. Light grays and bright yellows often fail.
- Following outdated “web-safe color” advice. The 216 web-safe colors date from 1990s screens that showed only 256 colors. Every modern screen shows millions of colors, so this rule no longer applies.
Frequently Asked Questions
What is the HTML color code for white?
White is #FFFFFF in hex, rgb(255, 255, 255) in RGB, and hsl(0, 0%, 100%) in HSL. You can also write #FFF or simply white.
What is the HTML color code for black?
Black is #000000 in hex, rgb(0, 0, 0) in RGB, and hsl(0, 0%, 0%) in HSL. The shorthand #000 and the name black also work.
How many color names does HTML support?
CSS supports 148 named colors. Some sources say 140 (counting gray and grey spellings once and leaving out rebeccapurple) or 147 (the older CSS3 list). All 148 work in every modern browser.
Are hex color codes case-sensitive?
No. #ff5733, #FF5733 and #Ff5733 all produce the same color. Color names are not case-sensitive either.
What is the difference between RGB and RGBA?
RGBA adds a fourth value, alpha, that controls transparency from 0 (invisible) to 1 (solid). In modern CSS, rgb() also accepts alpha, so rgb(255 0 0 / 0.5) and rgba(255, 0, 0, 0.5) are identical.
How do I add transparency to a hex code?
Add two more digits to the end. #FF000080 is red at about 50% opacity, #FF000040 at about 25%, and #FF0000FF is fully solid.
What does #FFF mean?
#FFF is the 3-digit shorthand for #FFFFFF, which is white. The browser doubles each digit, so #F00 means #FF0000 (red).
How many colors can HTML display?
Standard hex, RGB and HSL can describe 16,777,216 colors (256 × 256 × 256). Newer formats like OKLCH and color(display-p3 …) can reach even more colors on wide-gamut screens.
Is the tag still valid?
No. The tag is obsolete in HTML5. Browsers still display it, but you should set colors with the CSS color property instead.
Which color format is best for websites?
There is no single best format. Hex is the most common because design tools export it. HSL is the easiest for creating lighter, darker or muted versions of a color. Pick one format and use it consistently across your project.
Key Takeaways
- HTML color codes come in five main formats: hex, RGB, HSL, color names and modern formats like OKLCH.
- Hex, RGB and HSL can all describe the same 16.7 million colors. The difference is readability.
- CSS has exactly 148 named colors. Names found on other charts, like “Night” or “Black Cat”, do not work in code.
- Use HSL to build shades of a brand color by changing only the lightness.
- Always check text contrast: aim for at least 4.5:1 for normal text (WCAG AA).
READ NEXT:





