Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

color_swatch

60 sites No security coverage
View on drupal.org

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
7 months ago
Release cadence
0 days
Stability
100% stable

Releases

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