A comprehensive guide to color palettes - curated collections of colors used in design, art, and digital media to create harmonious, effective, and aesthetically pleasing visual compositions.
Color palettes are carefully selected collections of colors that work together harmoniously to create effective visual designs. They serve as the foundation for consistent color schemes in digital design, branding, web development, and artistic compositions. Understanding color palette theory and creation is essential for creating visually appealing and functional designs.
Create stunning, harmonious color palettes instantly with our AI-powered generator. Upload an image or choose a base color to get professional results.
AI-trained on thousands of artworks • Instant palette generation • Export in multiple formats • Perfect color harmony guaranteed
Color palettes are based on color theory principles that describe how colors interact with each other. These relationships are often visualized using the color wheel and mathematical relationships between hue, saturation, and lightness values.
// Color palette generator and analyzer
class ColorPaletteProcessor {
constructor() {
this.harmonyTypes = {
'monochromatic': { description: 'Variations of a single hue', colorCount: [3, 5, 7] },
'analogous': { description: 'Adjacent colors on color wheel', colorCount: [3, 4, 5] },
'complementary': { description: 'Opposite colors on color wheel', colorCount: [2, 4, 6] },
'triadic': { description: 'Three evenly spaced colors', colorCount: [3, 6, 9] },
'tetradic': { description: 'Four colors in two complementary pairs', colorCount: [4, 8] }
};
}
// Generate harmony-based palette
generateHarmonyPalette(baseColor, harmonyType, colorCount = 5) {
const baseHsl = this.rgbToHsl(baseColor.r, baseColor.g, baseColor.b);
let palette = [];
switch (harmonyType) {
case 'monochromatic':
palette = this.generateMonochromaticPalette(baseHsl, colorCount);
break;
case 'analogous':
palette = this.generateAnalogousPalette(baseHsl, colorCount);
break;
case 'complementary':
palette = this.generateComplementaryPalette(baseHsl, colorCount);
break;
case 'triadic':
palette = this.generateTriadicPalette(baseHsl, colorCount);
break;
case 'tetradic':
palette = this.generateTetradicPalette(baseHsl, colorCount);
break;
}
return palette.map((hsl, index) => {
const rgb = this.hslToRgb(hsl.h, hsl.s, hsl.l);
return {
rgb,
hsl,
hex: this.rgbToHex(rgb.r, rgb.g, rgb.b),
role: this.determineColorRole(index, palette.length),
accessibility: this.analyzeAccessibility(rgb)
};
});
}
generateMonochromaticPalette(baseHsl, count) {
const palette = [];
const { h, s, l } = baseHsl;
for (let i = 0; i < count; i++) {
const factor = (i / (count - 1)) - 0.5;
const newS = Math.max(0, Math.min(1, s + factor * 0.2));
const newL = Math.max(0.1, Math.min(0.9, l + factor * 0.3));
palette.push({ h, s: newS, l: newL });
}
return palette;
}
generateAnalogousPalette(baseHsl, count) {
const palette = [];
const { h, s, l } = baseHsl;
const hueSpread = 60;
for (let i = 0; i < count; i++) {
const hueOffset = (i / (count - 1) - 0.5) * hueSpread;
const newH = (h + hueOffset + 360) % 360;
palette.push({ h: newH, s, l });
}
return palette;
}
generateComplementaryPalette(baseHsl, count) {
const palette = [];
const { h, s, l } = baseHsl;
const complementH = (h + 180) % 360;
for (let i = 0; i < count; i++) {
const useComplement = i % 2 === 1;
const hue = useComplement ? complementH : h;
const lightness = 0.3 + (i / count) * 0.4;
palette.push({ h: hue, s, l: lightness });
}
return palette;
}
generateTriadicPalette(baseHsl, count) {
const palette = [];
const { h, s, l } = baseHsl;
const hues = [h, (h + 120) % 360, (h + 240) % 360];
for (let i = 0; i < count; i++) {
const hueIndex = i % 3;
palette.push({ h: hues[hueIndex], s, l });
}
return palette;
}
generateTetradicPalette(baseHsl, count) {
const palette = [];
const { h, s, l } = baseHsl;
const hues = [h, (h + 90) % 360, (h + 180) % 360, (h + 270) % 360];
for (let i = 0; i < count; i++) {
const hueIndex = i % 4;
palette.push({ h: hues[hueIndex], s, l });
}
return palette;
}
determineColorRole(index, totalColors) {
if (index === 0) return 'primary';
if (index === 1) return 'secondary';
if (index < totalColors - 1) return 'accent';
return 'supporting';
}
// Analyze accessibility
analyzeAccessibility(rgb) {
const luminance = this.calculateLuminance(rgb);
const whiteContrast = this.calculateContrastRatio(luminance, 1);
const blackContrast = this.calculateContrastRatio(luminance, 0);
return {
luminance,
contrastWithWhite: whiteContrast,
contrastWithBlack: blackContrast,
passesAA: whiteContrast >= 4.5 || blackContrast >= 4.5,
recommendedBackground: whiteContrast > blackContrast ? 'white' : 'black'
};
}
calculateLuminance(rgb) {
const { r, g, b } = rgb;
const rLinear = r <= 10 ? r / 3294 : Math.pow((r / 269 + 0.0513), 2.4);
const gLinear = g <= 10 ? g / 3294 : Math.pow((g / 269 + 0.0513), 2.4);
const bLinear = b <= 10 ? b / 3294 : Math.pow((b / 269 + 0.0513), 2.4);
return 0.2126 * rLinear + 0.7152 * gLinear + 0.0722 * bLinear;
}
calculateContrastRatio(lum1, lum2) {
const lighter = Math.max(lum1, lum2);
const darker = Math.min(lum1, lum2);
return (lighter + 0.05) / (darker + 0.05);
}
// Extract palette from image
extractPaletteFromImage(imageData, colorCount = 5) {
const pixels = this.samplePixels(imageData, 10);
return this.kMeansExtraction(pixels, colorCount);
}
samplePixels(imageData, quality) {
const { data } = imageData;
const pixels = [];
for (let i = 0; i < data.length; i += 4 * quality) {
if (data[i + 3] > 128) {
pixels.push({ r: data[i], g: data[i + 1], b: data[i + 2] });
}
}
return pixels;
}
kMeansExtraction(pixels, k) {
let centroids = this.initializeCentroids(pixels, k);
for (let iteration = 0; iteration < 10; iteration++) {
const clusters = this.assignPixelsToClusters(pixels, centroids);
centroids = this.updateCentroids(clusters);
}
return centroids.map(centroid => ({
r: Math.round(centroid.r),
g: Math.round(centroid.g),
b: Math.round(centroid.b)
}));
}
initializeCentroids(pixels, k) {
const centroids = [];
for (let i = 0; i < k; i++) {
const randomIndex = Math.floor(Math.random() * pixels.length);
centroids.push({ ...pixels[randomIndex] });
}
return centroids;
}
assignPixelsToClusters(pixels, centroids) {
const clusters = centroids.map(() => []);
for (const pixel of pixels) {
let minDistance = Infinity;
let closestCentroid = 0;
for (let i = 0; i < centroids.length; i++) {
const distance = this.colorDistance(pixel, centroids[i]);
if (distance < minDistance) {
minDistance = distance;
closestCentroid = i;
}
}
clusters[closestCentroid].push(pixel);
}
return clusters;
}
updateCentroids(clusters) {
return clusters.map(cluster => {
if (cluster.length === 0) return { r: 0, g: 0, b: 0 };
const sum = cluster.reduce(
(acc, pixel) => ({ r: acc.r + pixel.r, g: acc.g + pixel.g, b: acc.b + pixel.b }),
{ r: 0, g: 0, b: 0 }
);
return {
r: sum.r / cluster.length,
g: sum.g / cluster.length,
b: sum.b / cluster.length
};
});
}
colorDistance(color1, color2) {
return Math.sqrt(
Math.pow(color1.r - color2.r, 2) +
Math.pow(color1.g - color2.g, 2) +
Math.pow(color1.b - color2.b, 2)
);
}
// Color space conversion utilities
rgbToHsl(r, g, b) {
r /= 255; g /= 255; b /= 255;
const max = Math.max(r, g, b), min = Math.min(r, g, b);
const diff = max - min, sum = max + min;
const l = sum / 2;
if (diff === 0) return { h: 0, s: 0, l };
const s = l > 0.5 ? diff / (2 - sum) : diff / sum;
let h;
switch (max) {
case r: h = ((g - b) / diff + (g < b ? 6 : 0)) / 6; break;
case g: h = ((b - r) / diff + 2) / 6; break;
case b: h = ((r - g) / diff + 4) / 6; break;
}
return { h: h * 360, s, l };
}
hslToRgb(h, s, l) {
h /= 360;
if (s === 0) {
const gray = Math.round(l * 255);
return { r: gray, g: gray, b: gray };
}
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
};
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
return {
r: Math.round(hue2rgb(p, q, h + 1/3) * 255),
g: Math.round(hue2rgb(p, q, h) * 255),
b: Math.round(hue2rgb(p, q, h - 1/3) * 255)
};
}
rgbToHex(r, g, b) {
return '#' + [r, g, b].map(x => {
const hex = x.toString(16);
return hex.length === 1 ? '0' + hex : hex;
}).join('');
}
}Based on the color wheel and established relationships between hues. This method provides mathematically harmonious color combinations that are pleasing to the eye.
Colors extracted from photographs, artwork, or existing designs using algorithms like k-means clustering or median cut quantization.
Colors chosen based on cultural associations, brand guidelines, or specific use case requirements.
Palettes designed with accessibility standards in mind, ensuring sufficient contrast ratios for users with visual impairments.
Color palettes establish brand identity and emotional connections with audiences. Consistent use across all materials reinforces brand recognition and trust.
Room color palettes create specific moods and atmospheres, considering lighting conditions, space size, and intended use.
Seasonal color trends and coordinated collections rely on carefully planned color palettes that appeal to target demographics.
Explore these comprehensive pillar articles related to Color Palettes
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
A comprehensive guide to tetradic color schemes - sophisticated four-color harmonies that use two complementary pairs arranged in rectangular or square formations on the color wheel, providing maximum color variety while maintaining structured relationships essential for dynamic design compositions, brand systems, and advanced color theory applications.
Comprehensive guide to analogous color schemes - adjacent hues on the color wheel that create natural harmony, visual cohesion, and sophisticated design solutions through subtle color relationships and graduated transitions.
A comprehensive guide to split-complementary color schemes - sophisticated three-color harmonies that combine a base color with two colors adjacent to its complement, creating balanced visual contrast with reduced tension compared to direct complementary pairs, essential for refined design compositions, brand identity systems, and advanced color theory applications.
Discover more about Color Palettes and related color theory concepts
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
A comprehensive guide to tetradic color schemes - sophisticated four-color harmonies that use two complementary pairs arranged in rectangular or square formations on the color wheel, providing maximum color variety while maintaining structured relationships essential for dynamic design compositions, brand systems, and advanced color theory applications.
Comprehensive guide to analogous color schemes - adjacent hues on the color wheel that create natural harmony, visual cohesion, and sophisticated design solutions through subtle color relationships and graduated transitions.
A comprehensive guide to monochromatic color schemes - sophisticated single-hue harmonies that create unified visual experiences through systematic variations in saturation, lightness, and tonal relationships, essential for elegant design compositions, brand consistency, and advanced color theory applications requiring cohesive aesthetic unity.
A comprehensive guide to split-complementary color schemes - sophisticated three-color harmonies that combine a base color with two colors adjacent to its complement, creating balanced visual contrast with reduced tension compared to direct complementary pairs, essential for refined design compositions, brand identity systems, and advanced color theory applications.
Comprehensive guide to complementary colors - opposing hues on the color wheel that create maximum visual contrast, dynamic tension, and powerful design impact through scientific color relationships and perceptual phenomena.
Discover more color terminology and concepts in our comprehensive glossary.
Browse Full Glossary