Color Palettes from Images: How Extraction Works & Best Practices
Ever seen a photo with a perfect color scheme and wished you could steal it? You can — legally. Here is how palette extraction works, which images give the best results, and how to get those colors into your CSS in one click.
Try it right now — free, no upload:
Extract palette from an image →How extraction works
A photo contains millions of pixels but only a handful of dominant colors. Extraction algorithms find them in two steps. First, the image is sampled — every Nth pixel is read into a list of red/green/blue values. Then comes quantization: the classic median-cut algorithm looks at which color channel varies the most, splits the pixels in half at the median of that channel, and repeats until it has as many groups as you asked for. Each group is averaged into a single swatch, and the groups are ranked by how many pixels they contain — the biggest group is your most dominant color.
Fancier tools use k-means clustering, which starts with random guesses and iteratively refines them. It is slower but can produce slightly cleaner palettes on tricky images. For most design work, median-cut is plenty — and it runs instantly, even on a phone.
Best images for palettes
Not every photo yields a useful palette. The best sources are images with rich, varied color: landscapes, product shots, illustrations, film stills, packaging. What to avoid:
- Nearly single-color images — a white wall gives you twelve shades of white.
- Photos under harsh artificial light — sodium lamps tint everything orange.
- Heavy filters or Instagram presets — they compress the color range.
One technical note: JPEG compression shifts edge colors slightly. If you are matching an exact brand color, work from a PNG original. For mood boards and inspiration, JPEG is fine.
From palette to stylesheet
A row of swatches is nice. A :root block you can paste into globals.css is what saves time. Good extractors export directly to the formats developers use:
- CSS variables —
--color-1: #3D5AFE;etc. - Tailwind v4 theme —
@theme { --color-brand-1: … } - JSON tokens — for Figma or design systems.
Pair each swatch with a contrast check (WCAG ratio) so you know at a glance whether white or black text reads better on it — our tool shows this under every color.
Privacy: keep it in the browser
Many palette tools ask you to upload the image to their server. If it is client work, a logo, or a personal photo, that is an unnecessary exposure. Prefer a tool that does the whole pipeline — decode, sample, quantize — in your browser via the Canvas API. The pixels never leave your device, and you can confirm it: open your browser's Network tab while using the tool and watch for any image upload. There should be none.
Frequently asked questions
The image is decoded in your browser and its pixels are sampled. An algorithm called median-cut then groups similar colors: it finds the color channel (red, green, or blue) with the widest spread, splits the pixels at the median of that channel, and repeats until it has the requested number of groups. Each group is averaged into one swatch. More advanced tools use k-means clustering, which refines the groups iteratively for slightly cleaner results.
Photos with rich, varied color: nature shots, product photography, illustrations, movie stills. Avoid nearly single-color images (a white wall gives you shades of white) and photos shot under harsh artificial light, which tints everything orange or green and skews the palette.
Slightly. JPEG compression shifts colors at edges and in gradients, so if you need an exact brand-color match, use a PNG original. For general design inspiration the difference is negligible.
Yes. Individual colors cannot be copyrighted, so HEX codes pulled from any image are free to use commercially. Note the distinction: the palette is yours, but the image itself may still be copyrighted — do not redistribute someone else’s photo.
Export it as CSS custom properties and paste the :root block into your stylesheet, or as Tailwind @theme tokens for Tailwind v4. Our free extractor above generates both with one click, plus JSON for design tools.
Upload-based tools send your full image to a server. If the photo is client work or personal, prefer a tool that extracts colors 100% in your browser — the pixels never leave your device. You can verify this in your browser’s Network tab: no image upload should appear.
