Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Usage Milestone: Time Field for Drupal 8+ Module time_field crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Color Swatch

58 sites No security coverage Drupal 9–11 Color ecosystem
View on drupal.org

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.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Aug 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Core Release date
1.2.0 Stable 9–11 Aug 27, 2025
1.1.1 Stable 9–10 Aug 27, 2025