induwara.lk
induwara.lkDesign · Utility

Colour Palette Generator

Generate eight harmonious palettes from a base colour, or extract a six-colour palette from any photo using median-cut quantisation. Export to CSS variables, Tailwind v4, or JSON. No upload, no signup, runs entirely in your browser.

By Induwara AshinsanaUpdated May 11, 2026
Generate a colour paletteHarmonies · Image extraction

Parsed as HEX · #1A4FB8 · HSL(219.9°, 75.2%, 41.2%)

Quick swatches

Complementary

Two colours 180° apart on the wheel — maximum contrast.

2 colours
Export

Analogous

Three colours within a 60° arc — calm and cohesive.

5 colours
Export

Triadic

Three colours spaced 120° apart — bold and balanced.

3 colours
Export

Tetradic (rectangle)

Four colours in two complementary pairs — rich variety.

4 colours
Export

Square

Four colours spaced 90° apart — even, vivid coverage.

4 colours
Export

Split-complementary

Base plus the two neighbours of its complement — softer than pure complementary.

3 colours
Export

Monochromatic

Same hue, stepped lightness — quiet, hierarchy-friendly.

5 colours
Export

Tints & shades

Base lightened toward white and darkened toward black.

5 colours
Export

Harmonies follow the classic colour-wheel definitions (Adobe Color, Itten's colour theory): complementary +180°, triadic ±120°, tetradic +60/+180/+240°, square +90/+180/+270°, analogous ±30°, split-complementary at 150°/210°. Image extraction uses Heckbert's median-cut quantiser (1980). All processing runs in your browser — files never leave your device. Last verified 2026-05-11.

How it works

The generator does two distinct jobs, each grounded in well-defined mathematics rather than a black-box model.

Harmony rotation

A base colour you enter (or pick) is converted from sRGB to HSL using the W3C CSS Color Module Level 4 algorithm. The hue is then rotated by fixed degrees on the colour wheel to produce each named harmony:

  • Complementary: H + 180° (one opposite).
  • Triadic: H + 120°, H + 240° (three evenly spaced).
  • Tetradic (rectangle): H + 60°, H + 180°, H + 240° (two complementary pairs).
  • Square: H + 90°, H + 180°, H + 270° (four evenly spaced).
  • Analogous: H − 30°, H, H + 30° (a 60° arc).
  • Split-complementary: H, H + 150°, H + 210° (complement's two neighbours).
  • Monochromatic: same hue, lightness stepped from ~15% to ~85%.
  • Tints & shades: same hue and saturation, base lightness ± 30 points in steps.

Each rotated HSL value is converted back to sRGB (eight-bit per channel) and then to a hex string. Every conversion in this tool round-trips through RGB → HSL → RGB within 1/255 per channel for the brand colours, the RGB primaries, sky-blue, rebeccapurple, mid-grey, black, and white. The verifyRoundTrip() function in the source runs this check on every page load.

Image extraction (median-cut)

When you drop an image, the tool first downsamples it to a maximum of 200 px on its longest edge using the Canvas 2D high-quality resampler. That reduces the work to about 40,000 pixels even for a phone photo. Fully-transparent pixels are skipped, and the remaining RGB triples go into a single bucket.

The tool then repeatedly splits the bucket with the widest range — on the red, green, or blue axis, whichever has the largest spread — at its median position, until there are six buckets. Each final bucket is averaged to one representative RGB value. The six swatches are sorted by ITU-R BT.709 luma (darkest first) and deduplicated, then shown with a one-click Use as base action that pipes any extracted colour back into the harmony generator.

This is Paul Heckbert's median-cut algorithm from his 1980 MIT master's thesis — the same algorithm GIMP and the GIF format use. It produces palettes that look perceptually faithful to the source without any AI, training data, or upload.

Export formats

Each palette card offers four export targets: a plain HEX list (one colour per line), CSS custom properties (the :root { --x: #hex } block you can paste into a stylesheet), a Tailwind v4 @theme inline block using the --color-* token convention introduced in Tailwind's v4 theme rework, and JSON for design-token tooling. Click a chip and the snippet is on your clipboard.

Worked examples

The induwara.lk brand primary

From a base — Sapphire #1A4FB8

  1. RGB(26, 79, 184) → HSL(220°, 75%, 41%)
  2. Complementary: 220° + 180° = 400° → 40° → saffron amber
  3. Triadic: [220°, 220° + 120° = 340°, 220° + 240° = 460° → 100°]
  4. Analogous: [220° − 30° = 190°, 220°, 220° + 30° = 250°]
  5. All keep S = 75%, L = 41% — only the hue rotates.

Sanity check against the RGB primaries

From a base — Pure red #FF0000

  1. RGB(255, 0, 0) → HSL(0°, 100%, 50%)
  2. Complementary: 0° + 180° = 180° → cyan #00FFFF
  3. Triadic: [0°, 120°, 240°] → red, green, blue (the RGB primaries)
  4. Tetradic: [0°, 60°, 180°, 240°] → red, yellow, cyan, blue
  5. Hue wrap test: 359° + 30° = 389° mod 360 = 29° (valid).

Edge case: input pixels are 50% pure red, 50% pure green

From an image — two-colour input

  1. Initial bucket: R ∈ [0, 255], G ∈ [0, 255], B ∈ [0, 0]
  2. Longest axis = R (or G — tie). Sort pixels along that axis.
  3. Split at median → bucket 1 = all reds, bucket 2 = all greens.
  4. Average each bucket → RGB(255, 0, 0) and RGB(0, 255, 0).
  5. Sort by BT.709 luma ascending: red Y ≈ 54.2, green Y ≈ 182.4.
  6. Output = [#FF0000, #00FF00] — red first (darker), green second.

What happens when the base has zero saturation

From a base — Grey #808080 (no-chroma edge case)

  1. RGB(128, 128, 128) → HSL(0°, 0%, 50%)
  2. Saturation is 0 — there is no chroma to rotate.
  3. Every harmony produces the same #808080 four to six times.
  4. Solution: the helper text under the base input flags this so
  5. you switch to a colour with at least 10–20% saturation.

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.