How to Find the Nearest CSS Named Color to Any HEX Code
CSS has 148 named colors like cornflowerblue and dodgerblue. Find the nearest named color to any HEX code and when to use named colors in your stylesheets.
CSS Has Named Colors
CSS supports 148 named colors. Some are obvious: red, blue, black,
white. Some are specific: cornflowerblue (#6495ED), dodgerblue
(#1E90FF), tomato (#FF6347). Some are relics of early web history:
papayawhip, gainsboro, burlywood.
These names work anywhere a color value is expected:
.named-examples {
color: cornflowerblue;
background-color: papayawhip;
border: 2px solid tomato;
outline: 1px dashed mediumseagreen;
}
Named colors are easier to read and remember than hex codes. tomato is
more meaningful than #FF6347 when scanning a stylesheet. They also make
prototyping faster since you do not need to look up values.
But there are only 148 of them. The chances that your brand color matches one exactly are slim. Most projects end up with custom hex values, but named colors still have a role in your workflow.
The Named Color Palette, Grouped
Named colors are not random. They fall into recognizable groups that are useful on their own:
Grays: black, dimgray, gray, darkgray, silver, lightgray,
gainsboro, whitesmoke, white. Use these for borders, dividers, and
backgrounds without reaching for a hex code:
.card {
background: whitesmoke;
border: 1px solid gainsboro;
color: dimgray;
}
Reds: maroon, darkred, firebrick, crimson, red, tomato,
coral, indianred, lightcoral, salmon, darksalmon, lightsalmon.
The range covers deep burgundy (maroon) through bright red (red) to
warm pinkish reds (salmon).
Blues: navy, darkblue, mediumblue, blue, royalblue,
dodgerblue, deepskyblue, cornflowerblue, steelblue, lightsteelblue,
lightblue, powderblue, skyblue, lightskyblue, aliceblue.
This is one of the largest groups in the set and spans dark navies through
vivid mid-blues to near-white powder blues.
Greens: darkgreen, green, forestgreen, seagreen,
mediumseagreen, limegreen, lime, springgreen, mediumspringgreen,
lightgreen, palegreen, darkseagreen, yellowgreen, olivedrab,
olive, darkolivegreen.
You can build fairly complete monochromatic palettes from a single named color group. For a quick admin panel prototype, the gray group alone gives you text, border, background, and hover states:
.admin-panel {
background: whitesmoke;
color: dimgray;
border: 1px solid silver;
}
.admin-panel:hover {
background: gainsboro;
}
Finding the Closest Match
The Color Converter shows the nearest named color to any input. Enter a HEX, RGB, or HSL value. The converter identifies the closest named color by Euclidean distance in RGB space and displays both the name and the delta (how far apart the colors are).
Input: #FF6B6B
Nearest named color: lightcoral (#F08080)
Delta: small. The colors are very close.
Input: #1A2B3C
Nearest named color: midnightblue (#191970)
Delta: moderate. Noticeably different.
If the delta is small (under roughly 20 in RGB Euclidean distance), the named color is a practical visual substitute. If the delta is larger, you have the closest CSS name but not a visual match. The tool shows the delta number so you can decide.
/* Delta < 10: safe to substitute */
.brand-close { color: lightcoral; } /* was #FF6B6B */
/* Delta > 30: keep your hex code */
.brand-far { color: #1A2B3C; } /* midnightblue is too different */
Why Use Named Colors
- Readability:
background: aliceblueis self-documenting. Someone reading your CSS knows roughly what color to expect without a color picker. - Prototyping speed: set a quick background to
whitesmokeorlightgraywithout switching to a design tool. Layout first, refine colors later. - Education: named colors make CSS more approachable for beginners.
color: redis obvious.color: #FF0000requires explanation. - Debugging: a temporary
outline: 2px solid redis faster to type and more visible than a hex code.outline: 2px solid limeworks too. - Placeholder styles: during early development, use named colors as placeholders that are easy to search for and replace later:
/* TODO: replace with design system tokens */
.wip-component {
background: lavender;
border: 1px solid thistle;
color: darkslateblue;
}
A project-wide search for lavender or thistle finds every placeholder
that needs a real design token. That is harder to do with raw hex values.
When Not to Use Named Colors
- Brand colors: your brand blue is a specific hex code. A nearby named color is not close enough for brand identity.
- Design systems at scale: named colors do not compose into semantic
layers. Use CSS custom properties with names like
--color-primaryand assign hex or HSL values. - Dark mode:
blackandwhitelook harsh in dark interfaces. Use off-blacks like#1a1a2eand off-whites like#f5f5f5with specific values. - Precision requirements: accessibility guidelines require specific contrast ratios. You need exact color values to verify compliance with tools like the WebAIM contrast checker.
A Quick Named-Color Reference
Here are the most commonly used named colors from each group, with their hex equivalents:
| Name | Hex | Use |
|---|---|---|
| aliceblue | #F0F8FF | Page backgrounds |
| whitesmoke | #F5F5F5 | Card backgrounds |
| gainsboro | #DCDCDC | Subtle borders |
| silver | #C0C0C0 | Disabled text |
| gray | #808080 | Secondary text |
| dimgray | #696969 | Body text |
| tomato | #FF6347 | Attention / errors |
| gold | #FFD700 | Warnings / highlights |
| limegreen | #32CD32 | Success states |
| dodgerblue | #1E90FF | Links / actions |
| navy | #000080 | Dark headers |
| crimson | #DC143C | Critical alerts |
This small subset covers the most common UI needs in prototyping.
Try it yourself: open the Color Converter. Enter your favorite brand color as a HEX code. The tool shows the nearest CSS named color and the numeric delta between them. If the delta is small (under 20), you have a readable named substitute you can use during development. If the delta is large, stick with your hex value. Try a few colors from your current project to see which ones have close named equivalents.