Privacy choices

Hue Codex uses local settings and privacy-aware measurement.

Required storage keeps tools and your local workspace working. Analytics helps improve popular tools; stricter consent regions stay opt-in unless you allow it. Marketing and personalized ads stay off until you choose them.

Abstract WCAG contrast methodology workspace with dark and light sample panels, luminance ladders, color swatches, and pass/fail accessibility checks.

Methodology

How Hue Codex calculates WCAG contrast

Hue Codex uses WCAG 2.x relative luminance and contrast-ratio math for role-scoped foreground/background checks. Color Picker Repair V2 layers a bounded, alpha-preserving OKLab candidate search on that standards-based calculation.

StandardHue Codex heuristicApproximationBrowser-dependent

Short answer

Hue Codex calculates contrast from sRGB relative luminance, compares the unrounded raw ratio against WCAG thresholds, and rounds only the displayed ratio. Color Picker Repair V2 then evaluates exact serialized sRGB candidates against every supplied context; it is a deterministic Hue Codex optimization method, not a WCAG-defined repair algorithm or a full accessibility guarantee.

  • Normal text AA requires 4.5:1, normal text AAA requires 7:1, large text AA requires 3:1, and large text AAA requires 4.5:1.
  • WCAG large text means at least 18pt normal text or 14pt bold text, approximately 24px and 18.5px respectively in CSS pixels.
  • Meaningful non-text UI cues, focus indicators, icons, and graphical objects use a 3:1 adjacent-color target.
  • Focus Ring Contrast checks adjacent-color contrast for the ring against page and component colors; it does not validate WCAG 2.2 Focus Appearance size, area, or focused-vs-unfocused state-change requirements.
  • Pass/fail logic uses raw ratios before display rounding, so near-threshold values are not rounded into a pass.
  • Color Picker “minimal perceptual change” means the lowest Euclidean OKLab distance among passing serialized candidates evaluated by its bounded V2 search, not a global-nearest guarantee.
  • Legacy HSL lightness repair remains a separate opaque single-pair heuristic and is not presented as Color Picker perceptual repair.
  • Contrast does not prove usability by itself; text size, font weight, placement, state cues, and non-color signals still matter.

Standards status

These badges identify which parts of this methodology are standards-backed, draft-track, source-origin references, Hue Codex-specific, approximate, or dependent on browser behavior.

StandardHue Codex heuristicApproximationBrowser-dependent
StandardStable standard or standards-backed behavior used as authority, such as WCAG 2.2 and broadly implemented CSS Color 4 behavior.
Hue Codex heuristicHue Codex ranking, role hints, bands, labels, or workflow guidance rather than an external standard.
ApproximationModel or estimate with known limits, including CMYK, color-vision simulation, image palette extraction, or CSS duotone output.
Browser-dependentOutput depends on browser APIs, rendering, color management, canvas pixels, clipboard, download, or CSS support.

Formulas, choices, heuristics, and limits

This separates standards-based formulas from Hue Codex implementation decisions, product heuristics, and known limitations for this methodology.

Standards-based formulas

Formula, threshold, syntax, or data behavior taken from a cited standard. Primary and model sources can inform implementation, but they are not automatically standards.

  • WCAG relative luminance from encoded sRGB channels divided by 255, piecewise-linearized at the 0.04045 breakpoint, then weighted with 0.2126 red, 0.7152 green, and 0.0722 blue.
  • WCAG contrast ratio: (lighter luminance + 0.05) divided by (darker luminance + 0.05).
  • WCAG text and non-text thresholds: 4.5:1, 7:1, 3:1, and 4.5:1 for the relevant AA and AAA use cases.
  • WCAG non-text contrast uses 3:1 adjacent contrast for meaningful focus indicators; WCAG 2.2 Focus Appearance also defines separate size, area, and focused-vs-unfocused contrast requirements.

Implementation choices

How Hue Codex chooses to parse, normalize, round, export, or sequence calculations.

  • Parsed colors retain their alpha channel. When a contrast result depends on transparency, Hue Codex first resolves the visible foreground/background stack against the tool's explicitly stated reference canvas.
  • Contrast Checker composites a translucent background over white and then the translucent foreground over that rendered background. Opacity Calculator multiplies embedded source alpha by its alpha control and composites the result over the selected background before scoring.
  • Text contrast is evaluated from the source foreground and background colors, not sampled anti-aliased screenshot pixels.
  • Hue Codex compares raw ratios for pass/fail and rounds only the displayed ratio.
  • Color Picker Repair Methodology 2.0 keeps the selected color's alpha unchanged, evaluates one to four resolved opaque contexts, and revalidates every serialized sRGB candidate against the applicable raw threshold.
  • Color Picker repairs are selected-color-only recommendations. They do not change the chosen backgrounds, usage role, threshold, or exported alpha.

Hue Codex heuristics

Product rankings, bands, labels, suggestions, or role hints that are useful guidance but not external standards.

  • Strict Hue Codex heuristic recommendations and highest-contrast candidate ranking are product guidance, not WCAG requirements.
  • Legacy single-pair recommendations search HSL lightness and prefer the least-over-target passing color. HSL lightness distance is not described as perceptual distance.
  • Color Picker Repair Methodology 2.0 uses separate deterministic objectives for minimal OKLab change, hue preservation, and chroma preservation, with ordered tie-breakers and exact sRGB serialization checks.
  • Gradient and palette readability signals use sampled or candidate pairs to prioritize review work.

Known limitations

Caveats, edge cases, browser dependencies, approximations, or contexts the method does not prove.

  • Contrast alone does not prove accessibility or usability.
  • Repair 2.0 uses a bounded candidate search, not a mathematical global optimization. In a mixed light-and-dark context, a valid interior candidate can exist even when the current endpoint-seeded search reports that no shared repair was found.
  • A passing repaired color pair does not prove that a component, state, focus treatment, or complete interface conforms to WCAG.
  • Anti-aliasing, thin type, images, texture, gradients, and final component placement can change real readability.
  • Anti-aliased or smoothed text can appear lower contrast than the nominal CSS/source color pair, especially with thin or unusual fonts.
  • Focus Ring Contrast checks adjacent-color contrast only; it does not validate the full WCAG 2.2 Focus Appearance size, area, or state-change requirements.
  • Disabled controls, logos, incidental text, and decorative content can have WCAG exceptions that require judgment.

Representative automated fixture coverage

Hue Codex imports versioned JSON fixtures and tests the corresponding pure production functions directly. The groups below are the representative regression evidence most relevant to this methodology.

  • Contrast fixtures: Known ratios, threshold boundaries, symmetry, and unrounded pass/fail behavior. View the JSON fixtures.
  • Parsing fixtures: Accepted CSS color syntax, alpha behavior, clamping, invalid input, and out-of-gamut fallback cases. View the JSON fixtures.

What a pass means. A passing group confirms the named vectors and tested properties still match the documented implementation. It does not prove every possible input, final browser rendering, full accessibility conformance, profile-aware print output, or every downstream export consumer.

Inputs and normalization

StandardApproximationBrowser-dependent

Contrast tools accept concrete CSS colors including alpha HEX, RGB, HSL, HWB, Lab/LCH, OKLab/OKLCH, supported color() profiles, fixed named colors, transparent, and tool-generated colors. Base channels resolve to sRGB for WCAG luminance math, but alpha is retained until the visible foreground/background stack has been composited.

Opacity behavior is explicit per tool. Contrast Checker composites a translucent background over a white reference canvas, then composites the foreground over that rendered background before calculating contrast. Opacity Calculator multiplies embedded foreground alpha by the selected alpha control, resolves a translucent background over white, and then scores the final rendered pair. Gradient contrast is sampled from representative stops and midpoint colors on its stated reference surface, so it is a warning signal rather than proof for every pixel.

Tool-specific opacity behavior.
ToolOpacity handlingWhat to enter or review
Contrast CheckerComposites background over white, then foreground over the rendered backgroundEnter the authored pair; if the real page backdrop is not white, repeat the check with the final rendered colors for that backdrop
Opacity CalculatorComposites the transparent foreground over the selected background before contrast checksReview the resolved color, overlay visibility, and text contrast on the composited result

Formula and thresholds

Standard

Relative luminance is calculated by converting each 8-bit sRGB channel into a 0 to 1 encoded value, applying the WCAG sRGB linearization curve, then weighting the linear red, green, and blue channels with 0.2126, 0.7152, and 0.0722.

The WCAG 2.2 breakpoint for the piecewise sRGB channel conversion is 0.04045. Older WCAG references sometimes show 0.03928; Hue Codex uses 0.04045.

Contrast ratio is (lighter luminance + 0.05) divided by (darker luminance + 0.05).

Hue Codex compares the raw ratio with the target threshold. The displayed ratio is rounded to two decimal places for readability, but the raw value decides pass or fail.

Text contrast is evaluated from the source foreground and background colors obtained from the user agent, markup, or stylesheets, not from anti-aliased screenshot pixels. Anti-aliasing, font smoothing, thin strokes, and unusual fonts can make rendered text appear fainter than the nominal CSS color pair.

WCAG defines large-scale text as at least 18pt normal text or 14pt bold text, or equivalent size for CJK fonts. W3C Understanding SC 1.4.3 gives the CSS conversion as 1pt = 1.333px, so 18pt is approximately 24px and 14pt is approximately 18.5px.

WCAG relative luminance formula
For each 8-bit sRGB channel C8:
  CsRGB = C8 / 255

  if CsRGB <= 0.04045:
    Clinear = CsRGB / 12.92
  else:
    Clinear = ((CsRGB + 0.055) / 1.055) ^ 2.4

L = 0.2126 * Rlinear + 0.7152 * Glinear + 0.0722 * Blinear

contrast_ratio = (max(Lforeground, Lbackground) + 0.05)
               / (min(Lforeground, Lbackground) + 0.05)
WCAG contrast thresholds used by Hue Codex.
Use caseAA targetAAA target
Normal text4.5:17:1
Large text: 18pt normal or 14pt bold3:14.5:1
UI components and graphical objects3:1Not scored by Hue Codex

Focus ring checks

StandardHue Codex heuristic

WCAG 1.4.11 Non-text Contrast applies a 3:1 adjacent-color contrast target to visual information required to identify component states, including authored focus indicators.

WCAG 2.2 SC 2.4.13 Focus Appearance is a separate Level AAA criterion. It requires a visible focus indicator area at least as large as a 2 CSS pixel thick perimeter of the unfocused component or sub-component, and a 3:1 contrast change between the same pixels in the focused and unfocused states.

The Hue Codex Focus Ring Contrast tool checks contrast only: ring color against the page background and ring color against the component fill. It does not calculate focus-indicator area, prove the 2px perimeter-equivalent size, evaluate focused-vs-unfocused pixel changes, check obstruction, or verify that every keyboard-focusable component has a visible indicator.

What the Focus Ring Contrast tool does and does not validate.
Requirement areaHue Codex checkRemaining manual review
Adjacent contrastChecks ring versus page and ring versus component against the 3:1 UI/non-text targetVerify the actual adjacent colors in every final state and theme
Focus Appearance size and areaNot validated as conformanceConfirm the indicator area meets or exceeds the 2 CSS pixel perimeter-equivalent requirement
Focused versus unfocused state changeNot validated as conformanceCompare same pixels between focused and unfocused states and confirm the required 3:1 change
Focus visibility and coverageNot validated as conformanceTest every keyboard-focusable component, focus-visible behavior, obstruction, offset, shape, and responsive state

Legacy HSL lightness repair and other recommendations

Hue Codex heuristic

Highest-contrast candidates compare candidate foreground colors against the selected background and rank them by raw contrast ratio. This label means highest contrast within the offered candidate pool; it does not mean closest visual match to the source color.

The legacy closest-passing helper is the opaque, single-pair HSL-lightness suggestion family implemented by suggestMinimumContrastColor(). It searches HSL lightness steps from 0 to 100 in 0.1 increments while preserving normalized source HSL hue and saturation values. It chooses the passing candidate with the lowest raw ratio that still meets the requested target, then breaks ties by the smallest absolute HSL lightness distance from the source color.

This legacy helper does not optimize a perceptual-distance metric, preserve alpha, or validate multiple contexts. It is not the Color Picker Repair V2 method described below.

Strict Hue Codex heuristic uses 7:1 as a product heuristic for choosing one strict candidate across common text scenarios. It is not a separate WCAG category and it is not automatically the highest-contrast color.

Accessible pair finding ranks foreground/background combinations by pass state and contrast. The ranking is useful for screening palettes, but final roles still need real component review.

  • Search direction: dark to light, evaluating lightness 0.0, 0.1, 0.2, ... 100.0 without stopping early.
  • Hue and saturation: copied from the normalized source HSL value; only HSL lightness changes during the search.
  • Clamping and rounding: hue is normalized, saturation and lightness are clamped to valid HSL ranges, then RGB channels are rounded and clamped into six-digit sRGB HEX.
  • Closest means absolute HSL lightness distance from the source color, measured in percentage points; it does not mean Delta E, RGB distance, or OKLCH distance.
  • Strongest available fallback: if no candidate reaches the target, Hue Codex returns the highest raw-contrast candidate and marks the suggestion as not passing the requested target.
Hue Codex legacy repair and recommendation heuristics.
LabelRanking ruleStatus
Highest-contrast candidateHighest raw contrast within the offered text-candidate poolHue Codex heuristic; useful for candidate comparison, not a WCAG category
Legacy HSL lightness repairLowest raw ratio that still meets the target; HSL-lightness distance only breaks tiesOpaque, single-pair Hue Codex heuristic; not Color Picker Repair V2 and not perceptual-distance optimization
Strict Hue Codex heuristicClosest passing adjustment using a 7:1 target across common text scenariosHue Codex heuristic; useful when a single strict candidate is preferred
Strongest available fallbackHighest raw contrast when no candidate reaches the requested targetMarked as not passing the requested target

Color Picker contrast scope and alpha

StandardHue Codex heuristicBrowser-dependent

Color Picker first resolves the selected Usage into role-specific evidence. Body text, large text, meaningful icons, meaningful borders, focus indicators, interactive accents, surfaces, decorative color, and data series do not share one universal pass rule. Pass, fail, review required, incomplete, and not applicable remain distinct.

For applicable contrast cells, the selected foreground is composited over each exact resolved background with its preserved alpha. Raw ratios decide the result; displayed ratios are rounded afterward. A passing cell covers only the named foreground, background, role, alpha, and threshold.

Disabled content has exemptions and context-dependent treatment rather than one universal Color Picker pass. Focus-ring color alone does not prove focus-indicator size, area, visibility, obstruction, or state change. Data-series review also needs labels, patterns, ordering, separation, and color-vision checks. Decorative colors that carry no information do not acquire a contrast requirement merely because they were entered in the picker.

Color Picker Repair Methodology 2.0

Hue Codex heuristicApproximationBrowser-dependent

Color Picker Repair V2 is a deterministic, selected-color-only search. It receives one resolved sRGB source, one to four exact opaque background contexts, preserved foreground alpha, and one applicable target. It never changes a background, typography, focus geometry, state cue, label, or chart encoding.

The search builds a bounded OKLab a/b neighborhood around the source, samples it on a 13 by 13 grid, evaluates both OKLab lightness endpoints, bisects a passing endpoint path 22 times, serializes every evaluated candidate to six-digit sRGB, and locally refines the best serialized candidates in RGB with channel steps 16, 8, 4, 2, and 1.

Every returned repair must pass every supplied context after its exact uppercase six-digit sRGB value is reparsed and its preserved alpha is composited. The engine ranks full-precision metrics calculated from that serialized candidate; rounded display values do not decide the repair.

  • Candidate neighborhood radius: max(0.06, source OKLCH chroma x 0.7), clamped to 0.06 through 0.16.
  • Local refinement limit: at most 32 improvement iterations per RGB step.
  • Output gamut enforced by Repair V2: clipped and quantized sRGB.
  • Determinism: identical normalized inputs produce identical candidates and ordering; lexical uppercase HEX is the final tie-break.
  • Method version: color-picker-repair-v2; public methodology version 2.0, effective and last reviewed 2026-07-23.

Repair objectives and tie-breaking

Hue Codex heuristicApproximation

Minimal perceptual change is the lowest Euclidean OKLab distance multiplied by 100 among passing serialized candidates evaluated by V2. This is a perceptually oriented approximation inside a bounded search, not a globally nearest proof or a universal model of human vision. Alpha is fixed and is not part of the distance.

Preserve hue and Preserve chroma are ranking objectives, not exact equality constraints. Preserve hue uses circular OKLCH hue distance across zero and 360 degrees. Preserve chroma uses absolute OKLCH chroma change. Lightness, hue, or chroma may still move when the best passing serialized candidate requires it.

For achromatic resolved sRGB colors, the shared conversion path uses numeric hue zero rather than preserving a separate CSS none or undefined-hue marker. That zero is a serialization convention, not evidence of a meaningful red hue.

Repair V2 stable objective order.
ObjectiveRanking order before lexical HEX
Minimal perceptual changeOKLab Euclidean distance x100; lightness change; contrast overshoot; chroma change; circular hue change
Preserve hueCircular hue change; OKLab distance; lightness change; chroma change; contrast overshoot
Preserve chromaAbsolute chroma change; OKLab distance; lightness change; circular hue change; contrast overshoot

Multi-context, gamut, serialization, and failure

StandardHue Codex heuristicApproximationBrowser-dependent

All supplied contexts are hard pass constraints. Repair V2 does not average them or accept a majority. The Color Picker role model supplies the maximum finite applicable target to the repair call.

Selected foreground alpha is clamped to the valid range and preserved. Fully transparent foregrounds cannot be repaired by changing hidden RGB channels. A translucent background is resolved over the Color Picker reference canvas before the opaque context is sent to Repair V2.

The required-gamut and mapping-objective controls are decision and export metadata. They are not Repair V2 search inputs. Authored Display P3 or perceptual input is resolved to the selected serialized sRGB repair value; V2 does not optimize Display P3 coordinates.

If the bounded OKLab search has no passing candidate, Repair V2 locally stabilizes its strongest failure in serialized RGB. It moves only for fewer failed contexts or a strictly higher weakest-context raw ratio. A newly passing value enters the normal candidate-refinement path; otherwise the stabilized value remains explicitly labeled failed.

Bounded-search completeness. No repair returned means no passing candidate was found by the evaluated V2 search, including local failure stabilization. It does not prove no sRGB solution exists. The mixed black/white 4.5:1 fixture now records #777777 refining to passing #777676.

Accessibility scope. A repaired color pair does not certify a complete component or page. Final typography, geometry, interaction, labels, non-color cues, actual canvases, states, and assistive-technology behavior still require review.

Generated Color Picker repair examples

StandardHue Codex heuristicApproximation

These rows are assembled from the committed machine-readable fixture generated by the production parser, contrast engine, and Repair V2 implementation. Raw values, displayed values, deltas, alpha, serialized output, and every context remain available in the downloadable JSON.

Representative generated Repair V2 vectors.
FixtureSource and resolved contextsObjectiveGenerated result
repair-on-light-background#777777 on Light theme #FFFFFFminimal#777777 to #777676; weakest context 4.53:1; source weakest context 4.48:1
translucent-foregroundrgb(65 105 225 / 75%) on Light theme #FFFFFFminimalrgb(65 105 225 / 75%) to #0242D6; weakest context 4.5:1; source weakest context 3.08:1
hue-wrap-preserve-hue#E080A0 on Light theme #FFFFFFhue#E080A0 to #8B6F77; weakest context 4.53:1; source weakest context 2.7:1
near-threshold-serialization#F080A0 on Light theme #FFFFFFminimal#F080A0 to #C44D75; weakest context 4.5:1; source weakest context 2.53:1
impossible-multi-context#777777 on Light theme #FFFFFF and Dark theme #000000minimalNo repair returned; strongest evaluated #EF5EBD remains at 3:1; source weakest context 4.48:1
mixed-context-interior-refinement#777777 on Light theme #FFFFFF and Dark theme #000000minimal#777777 to #777676; weakest context 4.53:1; source weakest context 4.48:1

Edge cases and limits

StandardBrowser-dependent
  • A ratio of 4.499:1 does not pass a 4.5:1 threshold, even if it displays near 4.5 after rounding.
  • Hue Codex uses source colors for contrast math. Anti-aliased screenshots and subpixel-rendered glyph edges are not sampled as the pass/fail source of truth.
  • Anti-aliasing, thin type, image text, textured backgrounds, and gradients can reduce practical readability.
  • Disabled controls, logos, brand marks, and incidental text can have different WCAG treatment than ordinary readable UI text.
  • Color contrast does not replace labels, icons, focus visibility, state affordances, or color-vision review.

Validation checks

StandardHue Codex heuristic
Real HEX contrast checks used to validate threshold boundaries.
PairRaw ratioExpected result
#000000 on #FFFFFF21:1Maximum sRGB contrast; AA normal and UI/non-text pass
#FFFFFF on #00000021:1Reciprocal maximum contrast; swapping foreground and background does not change the ratio
#FFFFFF on #FFFFFF1:1Same foreground and background; contrast thresholds fail
#767676 on #FFFFFF4.542224959605253:1AA normal passes because raw value is at least 4.5
#777777 on #FFFFFF4.478089453577214:1AA normal fails because raw value is below 4.5
#595959 on #FFFFFF7.004729208035935:1AAA normal passes just above the raw 7:1 threshold
#949494 on #FFFFFF3.0334698257384747:1UI/non-text passes because raw value is at least 3
#959595 on #FFFFFF2.9953461357088114:1UI/non-text fails because raw value is below 3

Equations and repair pseudocode

StandardHue Codex heuristicApproximation

These equations and steps are the reproducible contrast path. Legacy HSL repair and Color Picker Repair V2 are separate Hue Codex heuristics layered on top of the standards-based contrast formula.

WCAG contrast equations
srgb_to_linear(channel_8bit):
  v = channel_8bit / 255
  if v <= 0.04045:
    return v / 12.92
  return ((v + 0.055) / 1.055) ^ 2.4

relative_luminance(hex):
  r, g, b = hex_to_rgb(hex)
  return 0.2126 * srgb_to_linear(r)
       + 0.7152 * srgb_to_linear(g)
       + 0.0722 * srgb_to_linear(b)

contrast_ratio_raw(foreground, background):
  fg = relative_luminance(foreground)
  bg = relative_luminance(background)
  lighter = max(fg, bg)
  darker = min(fg, bg)
  return (lighter + 0.05) / (darker + 0.05)

wcag_score(foreground, background):
  raw = contrast_ratio_raw(foreground, background)
  return {
    display_ratio: round(raw, 2),
    normal_AA: raw >= 4.5,
    normal_AAA: raw >= 7,
    large_AA: raw >= 3,
    large_AAA: raw >= 4.5,
    ui_AA: raw >= 3
  }
Legacy HSL lightness repair for one opaque pair
suggest_minimum_contrast_color(target, fixed, minimum_ratio = 7):
  target_hex = normalize_hex(target)
  fixed_hex = normalize_hex(fixed)
  target_hsl = rgb_to_hsl(hex_to_rgb(target_hex))
  closest_passing = null
  strongest_available_fallback = null

  # Search direction is dark to light.
  # Step size is 0.1 HSL lightness from 0.0 through 100.0.
  # Hue and saturation are copied from target_hsl for every candidate.
  # hsl_to_rgb normalizes hue, clamps s/l to valid ranges,
  # rounds RGB channels, and rgb_to_hex clamps to displayable sRGB.
  for step from 0 to 1000 inclusive:
    lightness = step / 10
    candidate = rgb_to_hex(hsl_to_rgb({
      h: target_hsl.h,
      s: target_hsl.s,
      l: lightness
    }))
    raw = contrast_ratio_raw(candidate, fixed_hex)
    distance = abs(lightness - target_hsl.l)
    # "Closest" means this absolute HSL lightness distance,
    # not Delta E, RGB distance, or OKLCH distance.

    # Strongest available fallback chooses highest raw contrast.
    # Tie-breaker: closest HSL lightness to the source.
    # Exact ties keep the earlier dark-to-light candidate.
    if strongest_available_fallback is null
       or raw > strongest_available_fallback.raw
       or (raw == strongest_available_fallback.raw
           and distance < strongest_available_fallback.distance):
      strongest_available_fallback = {candidate, raw, distance, lightness}

    # Closest passing adjustment chooses the lowest raw passing ratio.
    # Tie-breaker: closest HSL lightness to the source.
    # Exact ties keep the earlier dark-to-light candidate.
    if raw >= minimum_ratio:
      if closest_passing is null
         or raw < closest_passing.raw
         or (raw == closest_passing.raw
             and distance < closest_passing.distance):
        closest_passing = {candidate, raw, distance, lightness}

  if closest_passing exists:
    return closest_passing with possible = true
  return strongest_available_fallback with possible = false
Color Picker Repair V2 bounded serialized-candidate search
repair_v2(source, backgrounds[1..4], alpha, target):
  before = evaluate(serialized_srgb(source), backgrounds, alpha, target)
  if before passes every context:
    return unchanged

  passing = evaluate black and white boundaries
  radius = clamp(max(0.06, source_oklch_chroma * 0.7), 0.06, 0.16)

  for each point in a 13 by 13 OKLab a/b neighborhood:
    for endpoint_lightness in [0, 1]:
      endpoint = evaluate_serialized(endpoint_lightness, a, b)
      if endpoint fails any context:
        continue
      bisect source_lightness toward endpoint 22 times
      retain every serialized passing candidate

  if no passing candidate was evaluated:
    strongest = best failure by failed contexts, weakest ratio, distance, HEX
    stabilize strongest in serialized RGB at steps 16, 8, 4, 2, 1
      move only for fewer failures or a strictly higher weakest ratio
    if strongest now passes:
      retain it as a passing candidate
    else:
      return no repair plus the locally stabilized strongest failure

  for objective in [minimal_oklab, preserve_hue, preserve_chroma]:
    refine the best eight seeds in serialized RGB
      with signed channel steps 16, 8, 4, 2, 1
      and at most 32 improvements per step
    rank with full-precision objective metrics
    break a final tie with lexical uppercase HEX

  return up to three distinct passing serialized candidates

Reproducible test vectors

StandardHue Codex heuristic

These vectors use the WCAG relative-luminance formula and compare unrounded raw ratios against the relevant threshold. Displayed ratios can round to two decimals, but pass/fail must use the raw value.

WCAG contrast boundary vectors.
InputExpected raw ratioThreshold result
#000000 on #FFFFFF21:1Maximum sRGB contrast; AA normal and UI/non-text pass
#FFFFFF on #FFFFFF1:1Same foreground and background; contrast thresholds fail
#767676 on #FFFFFF4.542224959605253:1AA normal passes because raw value is at least 4.5
#777777 on #FFFFFF4.478089453577214:1AA normal fails because raw value is below 4.5
#949494 on #FFFFFF3.0334698257384747:1UI/non-text passes because raw value is at least 3
#959595 on #FFFFFF2.9953461357088114:1UI/non-text fails because raw value is below 3

Sources and standards

These references anchor the public standards, model origins, source records, and formats used by Hue Codex. Status badges distinguish stable standards, drafts, primary sources, model sources, Hue Codex heuristics, approximations, and browser-dependent behavior.

Tools using this methodology

These Hue Codex tools link to this methodology because they depend on the formulas, assumptions, limits, or data policy described here.

Report a calculation issue

If a result does not match the documented formula or fixture, send the exact input, tool settings, displayed result, expected result, precision mode, and browser details. Please do not include private images, personal information, or secrets.