Blog / Build with AI /

Building a colour palette tool with AI

Every web project starts the same way: someone says “make it feel fresh” and you’re staring at a blank colour picker. A palette tool won’t fix taste, but it can take the first ten minutes of dithering away.

This is a walk-through of how I’d build a small palette generator with an AI chatbot. The finished thing is one web page: you pick a base colour, press a button, and get five matching colours with their hex codes, each one copyable with a click. I’m describing a method and an example here, not claiming I shipped this exact tool.

If you’ve never built anything this way, start with building a tiny tool with AI, from idea to working page in an afternoon. This post follows the same shape, with a more visual result.

Why a palette tool is a good project

  • It’s visual, so you see straight away whether it works.
  • The maths is small and well known: colours can be described by hue, saturation and lightness, and a palette is mostly “move the hue around”.
  • It runs in a browser with no hosting and nothing to install.
  • If you work on websites, you’ll actually use it.

Step 1: say what it does in two sentences

A single HTML page with a colour picker. When I press “Generate”, it shows five colour swatches based on the picked colour. Each swatch shows its hex code, and clicking it copies the code.

If you can’t say it that plainly, trim it. “Save palettes to an account” and “export to Figma” are for another weekend.

Step 2: ask for the simplest version

A prompt I’d start with:

I’m a beginner. Write one HTML file with the CSS and JavaScript inside it, no libraries. It has a colour input and a Generate button. On click, it creates five swatches from the chosen colour using HSL: the original, two with the hue rotated by 30 degrees either way, and two complementary-style colours. Show the hex code on each swatch and copy it to the clipboard on click. Comment the code so I can learn from it.

You’ll get something like a colour input, a row of div elements, and a function that converts between hex and HSL. Save it as palette.html and open it in your browser.

The first thing to check is the conversion function. Colour maths is exactly the sort of code a chatbot can get subtly wrong. Pick pure red (#ff0000), and the result for that swatch should show red, not a slightly different red. If the “original” swatch doesn’t match what you picked, the hex-to-HSL conversion is off.

Step 3: ask what each part does

Don’t skip this. Paste the code back and ask:

Explain the hex-to-HSL function line by line, as if I’d never seen it. What does each variable hold?

You’ll learn that hue is an angle from 0 to 360, saturation and lightness are percentages, and that “rotating the hue” just means adding a number and wrapping round at 360. That one idea is the whole palette engine. Once you understand it, you can change the rules yourself: 180 degrees for a complement, 120 for a triad, small steps for a calm, related set.

Step 4: test with awkward input

Palette tools break at the edges. Try:

  • Black and white. Rotating the hue of a grey changes nothing, so you may get five identical swatches. That’s correct maths and a poor result. A fix is to nudge saturation and lightness as well.
  • Very light or very dark colours. Some swatches may come out almost invisible.
  • The same colour twice. Press Generate repeatedly; the palette should be consistent unless you add randomness on purpose.

Step 5: add the check that matters most

A palette that looks pretty can still be unreadable. Ask:

Add a contrast checker. For each swatch, show whether black or white text is more readable on it, and display the contrast ratio.

The accessibility guidelines (WCAG) set 4.5:1 as the minimum contrast ratio for normal body text. The formula uses the relative luminance of each colour. It’s longer than the hue maths, so test it against a tool you trust. Put black on white into your page and into an established contrast checker, and compare the numbers. White on black should give 21:1, and black on white the same.

If your colours fail, that’s useful information, not an error. It tells you which swatches are for backgrounds and which can carry text.

What went wrong, and what to watch

Things I’d expect:

  1. The copy-to-clipboard function fails when you open the file straight from your computer, because some browsers restrict clipboard access outside a secure page. If that happens, ask for a fallback, or serve the page through a local server or any ordinary HTTPS site.
  2. The chatbot over-engineers. If it hands you three files and a build step, say: “One file only, no build tools.”
  3. Colour theory claims. A chatbot may tell you a palette is “scientifically harmonious”. It’s a rule of thumb. Trust your eyes.
  4. Colours look different on different screens. A swatch on a cheap phone in bright sun isn’t the same as on a calibrated monitor. Check important brand colours on a couple of devices.

Where it’s useful for website work

If you manage sites, a tiny palette page saves real time. Say a client sends you a logo and a vague brief. You pick the main colour from the logo, generate a set, check contrast, and send back three options with hex codes. That’s a more professional reply than a screenshot of a colour wheel.

It also gives you something to keep. Paste the hex codes into your site’s style variables and note them in your site documentation, so the next person doesn’t guess.

A next step

Once the basic version works, add one thing at a time: a button to lock one swatch while regenerating the others, or an export that outputs CSS variables. Each addition is a separate, small prompt, which is how you keep control of what the AI changes.

What would you add first: saving palettes, or checking contrast against your own page background?