Extract a Color Palette From an Image

Drop in a photo or artwork and pull out its dominant colors as HEX codes or CSS variables. Choose how many colors you want, from 3 to 12; crop first if you only care about part of the picture.

How to Extract a Color Palette From a Photo (and Make It Usable)

Photographs are one of the best sources of color inspiration. A landscape at dusk, a market stall or a mid-century interior already contains colors that work together, because they came from the same light. Extracting a palette from a photo turns that harmony into HEX codes you can use. The extraction is automatic, but getting a useful palette takes a little judgement.

Color palette of five dominant colors extracted from a landscape photo

What “dominant colors” means

A typical 12-megapixel photo contains millions of pixels and often hundreds of thousands of unique colors, because every slight change in light creates a new value. A palette extractor reduces those to a handful of representative colors. This process is called color quantization, and it is the same problem image formats like GIF solved in the 1980s, when images had to be reduced to 256 colors.

There are several common approaches:

MethodHow it worksStrengthsWeaknesses
Bucketing (histogram)Round each pixel to a coarse grid and count how many land in each cellVery fast, predictableCan split one color across two buckets
Median cutRepeatedly split the color space along its widest rangeBalanced results, classic in GIF toolsFavors large areas
K-means clusteringStart with k guesses and move them to the center of nearby pixelsAccurate cluster centersSlower, results vary with starting points
OctreeBuild a tree of colors and merge the least-used branchesMemory efficientMore complex to implement

The image palette extractor above uses bucketing with averaging: it downscales the image, groups pixels into color buckets, averages each bucket and then merges colors that are too similar. For mood-board purposes the differences between methods are small; all of them find the colors that cover the most area.

The big catch: area is not importance

Automatic extraction ranks colors by how many pixels they cover. In most photos the biggest areas are backgrounds: sky, walls, floors, shadows. The color that makes the photo memorable, like a red scarf or a yellow taxi, may cover 2% of the frame and barely register.

That leads to two practical tips:

  1. Crop first. If you love the colors of one part of an image, crop to that part before extracting. The palette will reflect what you care about.
  2. Ask for more colors than you need. Extract eight to ten, then pick the four or five that work as a set. The less dominant colors are often the best accents.

From photo colors to a design palette

A raw extracted palette is a set of colors with no roles. To make it usable in a layout:

Find the neutrals. Most photos produce at least one near-white, one near-black and a mid-grey with a tint. These are your background and text candidates. Tinted neutrals pulled from a photo look more natural than pure greys.

Pick one hero color. Choose the most distinctive saturated color for buttons, links or key graphics. This is your 10% accent in the 60-30-10 rule, which we explain in our guide to building palettes with color theory.

Choose one or two supporting colors. Usually a softer version of the hero or a related hue, used for secondary surfaces and illustrations.

Adjust for function. Photo colors are often mid-tones, which fail contrast checks as text. Keep the hue but darken it for text, or lighten it for backgrounds. A color scale generator can produce the full range from one extracted color.

Which photos make good palettes

  • Images with a clear light source, like golden-hour landscapes, give warm, cohesive palettes.
  • Paintings and film stills are excellent because their colors were chosen intentionally. Cinematographers grade films with deliberate color schemes, often complementary teal and orange.
  • Product and interior photography gives refined, commercial palettes.
  • Flat illustrations and posters give exact colors with very little noise.
  • Busy snapshots under mixed lighting (for example indoor tungsten plus daylight) give muddy, inconsistent palettes.

Extracted palette versus color theory

ApproachStarting pointResult feelsBest for
Photo extractionAn image you likeNatural, mood-drivenBranding from photography, editorial, mood boards
Color harmony rulesOne base colorBalanced, systematicUI systems, quick consistent schemes
Random generationNothingSurprisingBreaking creative block

These approaches combine well. Extract a palette from a photo, choose your hero color, then use the palette generator to check which harmony it belongs to and fill any gaps. If the extracted colors feel too similar, a complementary accent from color theory can add the contrast you need.

Checking the result

Before committing, test the palette the same way you would any other:

  • Put text colors on background colors and run them through the contrast checker.
  • Check that important distinctions survive color blindness with the color blindness simulator.
  • Build a quick mock layout. Colors that look great as small swatches can be overpowering as full-width backgrounds.

Colors themselves cannot be copyrighted, so a palette extracted from any image is free to use. The image itself is another matter: use your own photos, licensed stock or public-domain artwork if you plan to display the source image alongside the palette, for example in a brand presentation.