To extract colors from CSS, run the file through a tool that searches for color values: a browser-based color extractor for a one-off file, the css-color-extractor CLI for repeatable audits, or a grep command with a color regex. For a live site, Chrome DevTools' CSS Overview lists the colors the page actually renders.
What counts as a color in a CSS file
A CSS color can be written in far more ways than hex codes, and any extraction method has to know which ones to look for. The CSS color type covers named colors, hex, rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch(), color(), color-mix() and light-dark(). It also includes keywords like currentColor and system colors such as Canvas and Highlight.
Hex alone has four forms: #RGB, #RGBA, #RRGGBB and #RRGGBBAA. The syntax is case-insensitive, so #00ff00 and #00FF00 are the same color, and #F09 equals #ff0099.
Named colors are a bigger group than most people expect. Beyond the 16 basic keywords, about 150 other colors have a keyword, and transparent is a shortcut for rgb(0 0 0 / 0%).
Option 1: Paste the file into a browser extractor
A browser-based CSS color extractor is the fastest way to pull colors out of a single stylesheet. You paste the CSS, the page scans the text, and you get a list of color values to copy.
Before you paste anything, check two things:
- Which formats it reads. Some tools list hex,
rgb()andrgba()only. Others addhsl()or named colors. - Where your CSS goes. A client-side tool processes the text in your browser tab. A server-side one uploads it.
The CSS color extractor on this site lists hex, rgb and rgba values. The tool code runs in the page, and the pasted stylesheet isn't sent anywhere by the site. If your theme leans on oklch() or named colors, use the CLI or grep methods below instead.
Option 2: Use the css-color-extractor CLI
The css-color-extractor package is a command-line tool that reads a stylesheet and prints its colors. Its README says it extracts named, hex, rgb, rgba, hsl and hsla colors, so it catches the keywords that regex-only tools miss.
Install the CLI globally:
npm install -g css-color-extractor-cliRun it on your file:
css-color-extractor styles.cssSort by hue to see near-duplicates side by side:
css-color-extractor styles.css --sort=hueExport the list for a design review:
css-color-extractor styles.css --format=json
Two more flags help: --color-format=hslString converts every value to one notation, and --without-grey drops grey-only rules. In the library version, setting sort to frequency orders colors by how often they appear, so the one-off shades worth folding into a token stand out.
Option 3: Extract colors from CSS with grep
grep is already installed on Linux and macOS, and it can pull colors out of a CSS file in one line. The grep manual explains the flags that matter here: -o prints only the matched parts, each on its own line, -E enables extended regular expressions, and -h drops the file name prefix.
Here's the command I use, with a count of how often each value appears:
grep -oEih '#[0-9a-f]+\b|(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\([^)]*\)' styles.css \
| tr 'A-F' 'a-f' | sort | uniq -c | sort -rn
The tr step lowercases the hex letters, so #0F766E and #0f766e are counted as one color. Swap styles.css for -r src/ to scan a whole folder.
A worked example: what each method misses
I ran each method on this small stylesheet:
:root {
--brand: #0f766e;
--brand-soft: #0f766e33;
}
#cafe { padding: 8px; }
.button {
background: var(--brand);
color: white;
border: 1px solid #0F766E;
}
.button:hover { background: rgb(13 148 136); }
.alert { color: oklch(62% 0.2 25); background: #fee; }
.muted { color: hsl(210 10% 45%); }
The grep command above printed this:
2 #0f766e
1 rgb(13 148 136)
1 oklch(62% 0.2 25)
1 hsl(210 10% 45%)
1 #fee
1 #cafe
1 #0f766e33
Three problems show up, and real stylesheets have all of them:
#cafeis a selector, not a color. Any ID made only of hex letters (#bad,#face,#add) matches a hex pattern. Read short matches before you trust them.whiteis missing. A pattern built for hex and color functions skips keywords, so you'd need a list of the named colors to catch them.var(--brand)isn't resolved. Text-based tools see the custom property name, not the value it points to. Here the value was still found because it's defined in the same file.
| Method | Named colors | 8-digit hex | oklch() |
Resolves var() |
Sees only used colors |
|---|---|---|---|---|---|
| Browser extractor (hex/rgb/rgba) | No | Depends on tool | No | No | No |
| css-color-extractor CLI | Yes | Not listed in README | Not listed in README | No | No |
| grep with the regex above | No | Yes | Yes | No | No |
| Chrome DevTools CSS Overview | Yes (computed) | Yes (computed) | Yes (computed) | Yes | Yes |
Option 4: Get the colors a live page actually uses
Chrome DevTools' CSS Overview panel lists the colors a page renders, after the browser has resolved variables and the cascade. Use it when you care what the page shows, not what the file says.
- Open the page and open DevTools.
- Go to More tools, then CSS Overview.
- Click Capture overview.
The Colors section groups colors by background, text, fill and border. Each color is clickable and lists the elements that use it. The same report also flags text with low contrast.
The catch is scope. CSS Overview reports what the current page renders in its current state, so colors used only on hover, in dark mode or on other routes won't appear unless you capture those states too.
Which method should you use?
The best method depends on whether you want the file's full palette or only what's visible. My take: run the CLI or grep first to see everything the stylesheet declares, then use CSS Overview on your main pages to find which of those values are actually rendered. Values that appear in the file but never in the overview are often dead code.
A linter stops a cleaned-up palette from drifting again. Stylelint's color-no-hex rule bans hex colors to enforce a convention, and color-named can flag values that have a named equivalent.
The real limitation of every file-based method is that CSS is text until a browser applies it. A tool reading the file can't tell you which rules ever match an element, and it can't follow a variable defined in another file. Someone still has to review the list by hand before it becomes a palette.
Once you have the list, a few related clean-up jobs usually follow: minifying the stylesheet for production, converting px values to rem while you're editing sizes, and deciding whether Prettier or an online formatter should own the formatting.
FAQ
Can I extract colors from a CSS file without installing anything?
Yes. Paste the stylesheet into a browser-based CSS color extractor, or use grep, which ships with Linux and macOS. Both read the file as text and list the color values they recognise.
Why does my color list include values that aren't colors?
A simple pattern for hex colors also matches ID selectors made of hex letters, such as #cafe or #bad. Check short hex matches against the selectors in the file before you add them to a palette.
How do I see which colors a live website actually uses?
Open Chrome DevTools, go to More tools, then CSS Overview, and click Capture overview. The Colors section groups the page's colors by background, text, fill and border, and clicking a color lists the elements that use it.
Do named colors like white or tomato count?
Yes. CSS has 16 basic color keywords plus about 150 more, and they are as valid as hex values. Many quick extractors skip them, so check whether your tool lists named colors.