{"id":152,"date":"2026-10-18T21:10:25","date_gmt":"2026-10-18T21:10:25","guid":{"rendered":"https:\/\/refracttools.com\/blog\/?p=152"},"modified":"2026-10-18T21:10:25","modified_gmt":"2026-10-18T21:10:25","slug":"colour-palette-from-image","status":"publish","type":"post","link":"https:\/\/refracttools.com\/blog\/ui-design\/colour-palette-from-image\/","title":{"rendered":"How to get a colour palette from an image"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To get a colour palette from an image, a palette tool groups the image&#8217;s pixels into clusters of similar colour, usually with k-means clustering, and reports the average colour of each cluster and how much of the image it covers. Three to five colours give a tight, brand-style palette; eight to twelve capture more detail. The <a href=\"https:\/\/refracttools.com\/image-colour-palette\/\">colour palette from image<\/a> tool does this in your browser, adds an eyedropper for exact colours, and checks every swatch for text contrast.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-takeaways is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">Key takeaways<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The most common colours in a photo are often its backgrounds and shadows, not its accents. Use an eyedropper for small, vivid details.<\/li>\n\n\n<li>Grouping colours in a perceptual space such as OKLab gives palettes that match what you see.<\/li>\n\n\n<li>Check each colour&#8217;s contrast before deciding which ones can carry text.<\/li>\n\n\n<li>Export as CSS custom properties, then build tints and shades from your key colours.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">How does a colour palette extractor work?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A photo can contain tens of thousands of distinct colours. A palette tool reduces them to a handful in four steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Sample the pixels.<\/strong> Large images are scaled down first; a few thousand pixels describe the colours just as well as millions.<\/li>\n\n\n<li><strong>Convert to a perceptual colour space.<\/strong> Refract uses OKLab, where equal distances look like equal differences to the eye. In plain RGB, two blues that look almost identical can be numerically far apart.<\/li>\n\n\n<li><strong>Cluster with k-means.<\/strong> The algorithm places k centres, assigns every pixel to the nearest one, moves each centre to the average of its pixels, and repeats until nothing changes much.<\/li>\n\n\n<li><strong>Report the results.<\/strong> Each centre becomes a swatch, and its share of pixels becomes the coverage percentage.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Refract starts the clustering from a fixed point, so the same image and settings always give the same palette, which matters when you need to recreate it later.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why doesn&#8217;t the palette include the colour I wanted?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Because k-means rewards area. A product photo on a white background will report white, grey and a few shades of the product; the small orange logo on the box might not make the list at all. Three ways to get it:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Increase the number of colours<\/strong> so smaller areas get their own cluster.<\/li>\n\n\n<li><strong>Sort by hue<\/strong> to see the full range rather than the biggest areas first.<\/li>\n\n\n<li><strong>Use the eyedropper.<\/strong> Click the exact pixel you want and add it to the palette.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Shadows and highlights add another twist. A red jacket in a photo contains bright red, mid red and near-black red, and the clusters may split it three ways or merge the dark part with other shadows. If a key colour looks muddy in the palette, pick it from a well-lit area with the eyedropper rather than relying on the cluster average.<\/p>\n\n\n<aside class=\"tool-card tool-card--inline\"><span class=\"swatch\" style=\"background:linear-gradient(90deg,#1e3a8a 0 25%,#f59e0b 25% 50%,#7c2d12 50% 75%,#fde68a 75%)\" aria-hidden=\"true\"><\/span><div class=\"tool-card__body\"><p class=\"tool-card__eyebrow\">Free tool<\/p><p class=\"tool-card__name\">Colour palette from image<\/p><p class=\"tool-card__blurb\">Extract the main colours from any image and export them as code.<\/p><\/div><a class=\"btn primary\" href=\"https:\/\/refracttools.com\/image-colour-palette\/\">Try it free <span aria-hidden=\"true\">\u2192<\/span><\/a><\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">How do you turn extracted colours into a usable palette?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Raw extracted colours are a starting point, not a finished system. A practical web palette needs a few roles:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Role<\/th><th>What to look for<\/th><th>Typical share of a layout<\/th><\/tr><\/thead><tbody><tr><td>Background \/ neutral<\/td><td>A light or dark, low-saturation colour from the image<\/td><td>Most of the page<\/td><\/tr><tr><td>Primary<\/td><td>The colour that most represents the image or brand<\/td><td>Buttons, links, key headings<\/td><\/tr><tr><td>Accent<\/td><td>A small, vivid colour, often found with the eyedropper<\/td><td>Highlights, badges, illustrations<\/td><\/tr><tr><td>Text<\/td><td>A very dark or very light neutral with strong contrast<\/td><td>All body copy<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Many designers use a rough 60-30-10 split between neutral, primary and accent as a starting point. Once you have your key colours, generate tints and shades so you have lighter and darker versions for hover states, borders and backgrounds. Our guide to <a href=\"\/blog\/ui-design\/oklch-color-palette-css\/\">building a palette with OKLCH<\/a> shows how, and the <a href=\"https:\/\/refracttools.com\/contrast-checker\/\">contrast checker and palette generator<\/a> builds a full 50\u2013950 scale from one colour.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-callout is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\"><strong>Contrast:<\/strong> Each swatch in the extractor shows its contrast ratio with white and with black text. 4.5:1 or more passes WCAG AA for normal text; 3:1 passes for large text and icons. Colours that fail both are decoration only. See <a href=\"\/blog\/ui-design\/wcag-contrast-ratio\/\">WCAG contrast ratios explained<\/a>.<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Getting colours from a website or a brand<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To match an existing website, take a screenshot and drop it in; the eyedropper reads exact pixel values. Bear in mind that screenshots can shift colours slightly if your display uses a wide-gamut colour profile, so confirm critical brand colours against the site&#8217;s CSS or the brand guidelines. For a mood board, combine several photos into one image first so the palette reflects the whole set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before committing to a palette, check it with the <a href=\"https:\/\/refracttools.com\/colour-blindness-simulator\/\">colour-blindness simulator<\/a>. Colours extracted from nature photos often include reds and greens of similar lightness, which can merge for people with colour vision deficiency; our guide to <a href=\"\/blog\/ui-design\/colour-blind-friendly-design\/\">designing for colour blindness<\/a> explains the fix.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Exporting the palette<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The extractor exports CSS custom properties, SCSS variables, a Tailwind colour object or JSON, or a PNG of the swatches for a mood board. Custom properties are the most flexible for the web:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:root {\n  --brand-sand: #e8d5b7;\n  --brand-sea: #2a6f97;\n  --brand-coral: #f07167;\n  --brand-ink: #13293d;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Give each colour a role-based name, such as <code>--color-primary<\/code>, once you have decided how it will be used. Names like <code>--blue-2<\/code> become confusing when the brand colour changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Try it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Drop a photo, logo or screenshot into the <a href=\"https:\/\/refracttools.com\/image-colour-palette\/\">colour palette from image<\/a> tool, choose how many colours you want, pick any extra details with the eyedropper and copy the code. The image never leaves your device.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Last checked: October 2026.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Sources: <a href=\"https:\/\/bottosson.github.io\/posts\/oklab\/\" rel=\"noopener\" target=\"_blank\">Bj\u00f6rn Ottosson: A perceptual color space for image processing (OKLab)<\/a>, <a href=\"https:\/\/www.w3.org\/WAI\/WCAG22\/Understanding\/contrast-minimum.html\" rel=\"noopener\" target=\"_blank\">W3C: Understanding SC 1.4.3 Contrast (Minimum)<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How palette extractors pick colours from a photo with k-means clustering, why they miss small accent colours, and how to turn the result into an accessible web palette.<\/p>\n","protected":false},"author":1,"featured_media":151,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_refract_tool":"image-colour-palette","footnotes":""},"categories":[24],"tags":[28,5,13],"class_list":["post-152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ui-design","tag-colour","tag-image-tools","tag-ui-design"],"_links":{"self":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":1,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/152\/revisions\/162"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media\/151"}],"wp:attachment":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}