gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Support for HCT Color Space in WordPress Block Themes

Open Jiwoon-Kim opened this issue 1 year ago • 2 comments

What problem does this address?

Currently, WordPress supports only RGBA, HSLA, and HEX color spaces. However, these models have limitations:

  • Inconsistent Perceptual Contrast: HSLA does not ensure consistent contrast between foreground and background colors, making WCAG accessibility compliance difficult.
  • No Built-in Dynamic Theming: Theme developers must manually implement light/dark mode toggles, leading to inconsistent experiences.
  • Lack of User-Customizable Colors: Users cannot dynamically adjust colors in a perceptually uniform way.

HCT (Hue-Chroma-Tone) color space solves these problems by providing better perceptual contrast, accessibility, and dynamic color adaptation.


What is your proposed solution?

1️⃣ Introduce HCT Color Space in WordPress Core

  • Integrate HCT (Hue-Chroma-Tone) alongside existing color models.
  • Enable better light/dark mode handling through perceptually uniform colors.
  • Allow themes to define custom color harmonies that adapt dynamically.

2️⃣ Enhance Accessibility & WCAG Compliance

  • Ensure consistent contrast ratios for text and UI elements.
  • Make dynamic color changes more visually predictable for users.

3️⃣ Enable Material Design 3 Color Utilities

  • Google’s Material Design 3 already utilizes HCT-based color generation.
  • Instead of reinventing the wheel, WordPress could leverage [Material Color Utilities](https://github.com/material-foundation/material-color-utilities) to handle color transformations.

4️⃣ Alternative Approach: Theme-Level Implementation

  • If Core implementation is not feasible, allow themes to define their own color spaces without modifying WordPress Core.

🔗 References:

Would love to hear thoughts on this! 🚀


What problem does this address?

What is your proposed solution?

Jiwoon-Kim avatar Apr 02 '25 16:04 Jiwoon-Kim

What Problem Does This Address? Currently, WordPress only supports color values in RGBA, HSLA, and HEX formats. While functional, these color spaces have several shortcomings:

Inconsistent Perceptual Contrast HSLA and RGB do not maintain consistent contrast across different hues and tones.

This makes WCAG compliance for accessibility a manual and error-prone process.

No Built-In Dynamic Theming Theme developers must manually implement light/dark mode toggles.

This results in inconsistent and often inaccessible user experiences.

Lack of Perceptual Color Control for Users End-users and site admins cannot adjust or preview color changes in a way that preserves harmony or contrast.

Current tools do not support dynamic or context-aware color generation.

What Is the Proposed Solution? Introduce the HCT Color Space in WordPress Core Integrate support for HCT (Hue–Chroma–Tone), a perceptual color model used in Material Design 3.

HCT ensures consistent visual contrast and aesthetic harmony across various backgrounds and themes.

Enables intelligent, automatic color theme generation and transitions (like dynamic light/dark modes).

Improve Accessibility & WCAG Compliance HCT provides more predictable contrast between foreground and background elements.

This supports accessibility goals and makes it easier for themes to comply with WCAG 2.1+ out of the box.

Leverage Material Color Utilities Use Google’s Material Color Utilities library for generating HCT-based palettes.

This avoids reinventing the wheel and aligns with established design frameworks.

Enables features like tonal palettes, dynamic theming, and content-aware background styling.

Fallback or Alternative: Theme-Level Integration If Core-level implementation is too ambitious for now, allow theme developers to register custom color spaces and inject HCT-driven color utilities.

Could be exposed via theme.json or block styles registration.

References & Resources Material 3 Color System

Material Color Utilities GitHub

WCAG Contrast Checker

sonali195 avatar Apr 10 '25 05:04 sonali195

Bringing HCT and Material Color Utilities into Core probably isn’t the right fix.

Browsers can’t render hct(), so every value has to be converted to hex or sRGB before it reaches the page. Core processes theme.json in PHP, and there’s no official PHP port of Material Color Utilities, so WordPress would have to maintain an unofficial one.

Modern browsers support OKLCH natively, and it gets most of the perceptual benefit without an external library.

The bigger problem looks like the editor’s color tools. From reading the code, the color picker and palette don’t parse oklch() or color-mix() and seem to fall back to #000000. The contrast checker then works from the wrong color.

A cleaner path would be to update @wordpress/components (color picker, palette, contrast checker) to handle native CSS color formats, or at least fail visibly, and treat palette generation from a seed color (where HCT could fit) as an opt-in plugin, not a Core color space.

sarthaknagoshe2002 avatar Oct 23 '26 19:10 sarthaknagoshe2002