Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module provides a more flexible alternative to Drupal's core color module. It allows themes to define color swatches and placeholders in their `.info.yml` file, which are then rendered into inline CSS using Twig templates. This approach offers greater control and easier management of theme colors compared to the core module.

This is an alternative for the Drupal Core color module and color scheme. In my personal opinion this is somewhat more flexible. The reason is that the generated css is not compiled as a file (could be added perhaps later if this would have clear benefits), but added as inline css.

Also the css works through rendering of a twig file with a theme function. Which gives more control from preprocess functions, and twig template overrides on a theme level.

The swatches and settings can be defined in the theme info.yml which is easier for a lot of themers instead of writing php.

And we have a hook to change the active swatch if you want to apply some custom logic in your project.

The core color module generates a color.css file. A single file, no variants or something. Also it does a lot of stuff with images and image slices. Feels a bit outdated in this day and age.

This module is purely focused on supplying a css with the chosen colors. Which works excellent using css custom properties for instance.

How it works:

Add something like this in your themes info.yml.

color-swatch:
  placeholders:
    - primary
    - secondary
    - tertiary
  default: 'default'
  swatches:
    default:
      primary: '#FFFFFF'
      secondary: '#FFFF00'
      tertiary: '#FF0000'

What you do is
- define a set of placeholders, that you can use in a twig file (color-swatch-css.html.twig) to generate your own css.
- define a set of available default swatches with colors for the defined placeholders.
- choose a default from these swatches.

This results in a new set of form fields in your themes form. To determine one of the available swatches, or create a custom swatch through the ui.

You can override the twig file that generates the css with this file color-swatch-css.html.twig in you theme. The default template looks like this:

:root {
{% for placeholder in color_swatch.placeholders() %}
  --color-{{ placeholder }}: {{ color_swatch.hex(placeholder) }};
  --color-{{ placeholder }}-hue: {{ color_swatch.hue(placeholder) }}deg;
  --color-{{ placeholder }}-lightness: {{ color_swatch.lightness(placeholder) }}%;
  --color-{{ placeholder }}-saturation: {{ color_swatch.saturation(placeholder) }}%;
  --color-{{ placeholder }}-contrast-ratio:{{ color_swatch.contractRatio(placeholder) }};
  --color-{{ placeholder }}-rgb: rgb({{ color_swatch.rgb(placeholder).r }}, {{ color_swatch.rgb(placeholder).g }}, {{ color_swatch.rgb(placeholder).b }})
{% endfor %}
}

The generated css is than included inline in your html output of the page.

Activity

Total releases
2
First release
Aug 2025
Latest release
10 months ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Slowing

Releases

Version Type Release date
1.2.0 Stable Aug 27, 2025
1.1.1 Stable Aug 27, 2025