How to Create a Colour Palette From a Photo (K-Means vs Median Cut)

Pull the dominant colours out of any photo, see how k-means and median cut pick them, and turn the palette into accessible CSS or Tailwind colours.

Updated September 29, 2026 5 min read

Use the free Color Palette from ImageExtract the dominant colours of any photo as HEX, RGB or HSL

Some of the best colour schemes are not invented; they are found. A photo of a coastline, a product shot, a client's shop front or a favourite painting already contains colours that work together. Pulling those colours out gives you a palette for a presentation, a website theme, a brand refresh, social templates or an interior mood board that is guaranteed to feel coherent with the image that inspired it.

Doing it by eye with a colour picker is slow and surprisingly unreliable, because every pixel is a slightly different shade. Palette extraction groups thousands of colours into a handful of representative ones. This guide explains how that works, the difference between the two common methods, and how to turn the result into something usable in code and design tools.

How palette extraction works

A 12-megapixel photo can contain hundreds of thousands of distinct colours. Palette extraction treats each pixel as a point in colour space, with red, green and blue as three axes, and looks for clusters. Each cluster becomes one swatch, usually its average colour, and the share of pixels in that cluster tells you how dominant it is.

To keep this fast, the image is first shrunk; a few hundred pixels across is plenty to find the main colours. Fully transparent pixels are ignored.

K-means clustering

K-means starts with a set of candidate colours, assigns every pixel to the nearest one, moves each candidate to the average of its pixels, and repeats until things settle. It is excellent at finding the most common colours, which makes it the better choice for photographs: the result reflects what the photo mostly looks like.

Its weakness is that small but striking accents, such as a red umbrella in a grey street, may be absorbed into a larger cluster and disappear.

Median cut

Median cut repeatedly splits the colour space in half along the axis with the widest range, until it has the requested number of boxes, then averages each box. Because it divides by spread rather than by popularity, it keeps small accent colours more often. It was originally used to reduce images to limited palettes, such as for GIF files.

K-means Median cut
Favours Dominant colours Colour variety
Accent colours Can be lost More often kept
Best for Photos, mood boards Illustrations, logos, finding accents

Trying both on the same image is quick and often reveals a colour you would otherwise miss.

Extract a palette in your browser

The Color Palette from Image tool runs on your device and gives you code-ready output.

  1. Open Color Palette from Image and drop a photo onto the page, or paste one with Ctrl+V.
  2. Set the Number of colours (3-12).
  3. Choose a Method: K-means for photos or Median cut to keep accents.
  4. Choose a Colour format: HEX, RGB or HSL.
  5. Check the proportion bar under the image, which shows how much of the picture each colour covers, and the swatches below with their percentages.
  6. Click any swatch to copy its value.
  7. Use the tabs, CSS variables, SCSS, Tailwind or JSON, to copy or download the whole palette.

The CSS output uses variables such as --color-1, and the Tailwind snippet lists the colours under a palette key with 100, 200 and so on, ready to paste into your configuration and rename.

Other ways to build a palette

A colour picker for exact pixels

If you need the exact value of one specific spot, such as a logo colour in a screenshot, a picker is better than extraction. Image Color Picker lets you click individual pixels, and How to Find the Exact Colour Code of Any Pixel in an Image explains why readings vary across an image.

Design software

Adobe's colour tools, Figma plugins and Canva can generate palettes from images, often with mood presets such as "bright" or "muted". They are handy if you already work there.

By eye

Designers often pick a palette manually: one dominant neutral, one or two supporting colours and one accent. Extraction gives you the candidates; your judgement picks the combination.

Turning a palette into a usable colour scheme

Assign roles

A palette of six colours is not yet a design system. Decide which colour is the background, which is for text, which is the primary button and which is an accent used sparingly. A common guideline is to use a dominant colour for most of the area, a secondary colour for a smaller share and an accent for a small highlight.

Check contrast

Colours that look lovely together in a photo often fail readability when used for text. Test every text and background pair with Color Contrast Checker against WCAG contrast guidelines, and darken or lighten a colour where needed.

Build tints and shades

Real interfaces need lighter and darker versions of each colour, for hover states, borders and backgrounds. HSL makes this easy: keep the hue, change the lightness. Color Converter helps move between HEX, RGB and HSL.

Mind printing

Screen colours (RGB) do not always print the same (CMYK). For print jobs, treat the extracted values as a starting point and check with your printer's proofs.

Tips and troubleshooting

The palette is all browns and greys

Many photos are dominated by neutral tones. Increase the number of colours, switch to median cut, or crop to the most colourful part of the photo with Image Cropper first.

Two swatches look almost the same

The image may have a large area of one colour. Reduce the number of colours, or accept that it is genuinely dominant.

Colours look duller than the photo

Swatches are averages, which smooths out bright highlights. Increase saturation slightly when building the final scheme, and keep contrast in mind.

Results change slightly each time

K-means depends on its starting points, so small differences between runs or settings are normal. Pick the version you like and save it.

Frequently asked questions

How do I get a colour palette from a picture?

Upload the picture to a palette extractor, choose how many colours you want, and copy the resulting HEX, RGB or HSL values. Our tool also exports CSS, SCSS, Tailwind and JSON.

What is the difference between k-means and median cut?

K-means finds the most common colours, which suits photos. Median cut splits the colour range evenly, so it keeps small accent colours more often.

How many colours should a palette have?

Five or six is a practical size for most designs: a background, a text colour, one or two main colours and an accent. Extract more if you want options to choose from.

Can I use an extracted palette as brand colours?

Yes, as a starting point. Assign clear roles to each colour and check text contrast before adopting it, since photo colours are not always readable as text.

Is my photo uploaded?

No. The image is analysed in your browser, so private or unreleased images stay on your device.

Try it now: Color Palette from Image

Loading tool…