User Rating 0.0 ā˜…ā˜…ā˜…ā˜…ā˜…
Total Usage 0 times
Category CSS Tools
0 colors | Unsorted
Add colors to begin sorting
Is this tool helpful?

Your feedback helps us improve.

ā˜… ā˜… ā˜… ā˜… ā˜…

About

Arranging colors in a visually coherent order is a non-trivial computational problem. A naive alphabetical sort of hex codes produces chaotic sequences because hexadecimal notation encodes R, G, B channels sequentially, not perceptually. Human vision perceives color difference non-linearly. Two colors with a Euclidean RGB distance of 50 may look identical, while another pair at the same distance looks jarringly different. This tool converts colors into perceptually uniform spaces (HSL, CIE LAB) before sorting. The LAB-based perceptual sort uses a nearest-neighbor heuristic on ΔE* distances, approximating the traveling salesman problem to produce the smoothest possible gradient from an arbitrary set of colors.

Incorrect color ordering in UI design causes visual noise, reduces scannability, and breaks aesthetic coherence in design systems. This is especially critical when building theme palettes with 20+ tokens. The step-sort algorithm groups colors into 8 hue bands and sorts within each band by luminance, mimicking how physical paint swatches are organized. Note: perceptual sorting assumes a D65 illuminant and a 2° standard observer. Results may not match appearance under non-standard lighting conditions.

color sorter palette organizer color sorting tool hue sort luminance sort color palette CSS colors color order

Formulas

Relative luminance per WCAG 2.1 (used for luminance sort):

Y = 0.2126Rlin + 0.7152Glin + 0.0722Blin

where each linearized channel is computed as:

Clin =
{
CsRGB12.92 if CsRGB ≤ 0.04045(CsRGB + 0.0551.055)2.4 otherwise

CIE LAB perceptual distance between two colors:

Ī”E* = √(L1 āˆ’ L2)2 + (a1 āˆ’ a2)2 + (b1 āˆ’ b2)2

where L* is perceptual lightness (0 - 100), a* is the green - red axis, and b* is the blue - yellow axis. RGB → LAB conversion goes through CIE XYZ with D65 reference white Xn = 95.047, Yn = 100.0, Zn = 108.883.

HSL hue extraction from RGB:

H = 60° Ɨ
{
G āˆ’ BĪ” mod 6 if max = RB āˆ’ RĪ” + 2 if max = GR āˆ’ GĪ” + 4 if max = B

where Ī” = max(R,G,B) āˆ’ min(R,G,B). Step sort quantizes H into 8 bands of 45° each, then sorts by L within each band.

Reference Data

Sort MethodColor SpacePrimary KeySecondary KeyBest ForTime Complexity
HueHSLH (0 - 360°)LRainbow gradientsO(n log n)
SaturationHSLS (0 - 100%)HVivid → muted orderingO(n log n)
LightnessHSLL (0 - 100%)HDark → light rampsO(n log n)
LuminanceRGB (linear)Y (0 - 1) - Accessibility contrastO(n log n)
Red ChannelRGBR (0 - 255)G, BWarm tone isolationO(n log n)
Green ChannelRGBG (0 - 255)R, BNatural/organic tonesO(n log n)
Blue ChannelRGBB (0 - 255)R, GCool tone isolationO(n log n)
Step SortHSLHue band (8 groups)L within bandPaint swatch layoutO(n log n)
Perceptual (ΔE*)CIE LABNearest ΔE* neighbor - Smoothest visual gradientO(n2)
ReverseAnyCurrent index (desc) - Flip current orderO(n)
Shuffle - Fisher-Yates random - RandomizationO(n)

Frequently Asked Questions

Hex notation encodes colors as concatenated R, G, B channel bytes. Lexicographic sorting treats this as a single base-16 number, meaning #0000FF (pure blue) sorts before #00FF00 (pure green) and #FF0000 (pure red). The result interleaves hues chaotically because the encoding does not map to any perceptual color axis. Sorting by HSL hue or CIE LAB distance produces visually meaningful sequences.
Hue sort arranges colors along the color wheel (0-360°) and works well for rainbow-like palettes with varied hues. It fails with near-neutral colors (grays, whites, blacks) because their hue values are arbitrary. Perceptual sort using CIE LAB Ī”E* minimizes the visual jump between adjacent colors regardless of saturation or lightness. Use it when your palette contains a mix of chromatic and achromatic colors, or when you need the smoothest possible gradient for data visualization.
Step sort divides the 360° hue wheel into 8 equal bands of 45° each: red (0-45°), orange-yellow (45-90°), yellow-green (90-135°), green (135-180°), cyan (180-225°), blue (225-270°), purple (270-315°), and magenta (315-360°). Within each band, colors are sorted by lightness (dark to light). Colors with saturation below 10% are classified as neutral and placed in a separate group sorted by lightness only. This mimics physical paint swatch organization found in hardware stores.
The tool caps input at 500 colors to maintain responsive drag-and-drop interaction. Sorting algorithms run in O(n log n) time for most methods, but perceptual Ī”E* sort uses an O(n²) nearest-neighbor heuristic. At 500 colors this means up to 250,000 distance calculations. For sets above 100 colors, sorting is offloaded to a Web Worker to prevent UI thread blocking. If you need to sort thousands of colors, export the sorted result as JSON and process programmatically.
Achromatic colors (where R = G = B) have undefined hue in HSL space. Most implementations assign H = 0° by default, which places all grays in the red band. This tool detects colors with saturation below 2% and assigns them a synthetic hue of -1, forcing them to the beginning or end of the sorted array. For best results with gray-heavy palettes, use luminance sort or step sort, which handles neutrals explicitly.
Yes. Input hex colors are assumed to be in sRGB color space. The tool applies inverse sRGB companding (gamma decoding) before converting to linear RGB, then transforms to CIE XYZ using the sRGB matrix with D65 illuminant reference white (X = 95.047, Y = 100.0, Z = 108.883). The XYZ values are then converted to LAB using the standard cube-root transfer function with a linear segment below ε = 0.008856. This ensures Ī”E* values are perceptually meaningful.