Part of the jedee wiki — An LLM wiki, written by Claude Code, about the methods and techniques behind this site.
Duotone
A duotone maps an image’s tones onto two colors: the shadows take a dark color, the highlights a light one, and everything between is a blend of the two. It started as a print technique (two inks on one plate) and became a web fashion in the 2010s through Spotify’s campaigns. On the web it is usually built with blend modes rather than a pre-made image, so the colors can come from design tokens and change on hover.
Two layers and a grey image
The common CSS recipe stacks two colored layers over a greyscale image, using mix-blend-mode:
.tile { position: relative; isolation: isolate; }
.tile img { filter: grayscale(1); }
.tile::before,
.tile::after { content: ''; position: absolute; inset: 0; z-index: 1; }
/* whites become the light color, black stays black */
.tile::before { background: var(--duo-light); mix-blend-mode: multiply; }
/* blacks are lifted to the dark color */
.tile::after { background: var(--duo-dark); mix-blend-mode: lighten; }multiply darkens everything toward the light color, so white turns into it and black stays black. lighten then keeps whichever is lighter per channel, so pure black becomes the dark color. isolation: isolate keeps the blending inside the tile instead of mixing with the page behind it.
Every part of this can be animated. filter: grayscale() interpolates, and so does the layers’ opacity, so the duotone can fade in over the real image on hover and out again.
⚠️ The z-index on the layers is not optional. An element with a filter creates a stacking context and paints as if it were positioned, in source order. ::before comes before the img in the tree, so without a z-index the grey image paints on top of the light layer and hides it. The page still looks tinted, because ::after comes after the image and still shows, so the missing layer is easy to miss: the duotone just looks dull.
The two colors decide how dark the result is. A light end mixed with white gives highlights brighter than the original image; a light end that is the pure color, over a near-black dark end, gives a duotone darker than the image itself.
In jedee
The cover grids (Jams, the genre pages, Reading, Watching) use it in partials/cover-grid.njk and local/cover-grid.css. Each tile is painted in its post’s color family and shows the real cover; hovering brings the duotone in, with the title and artist at the bottom left, the slight scale() gated behind prefers-reduced-motion: no-preference, and the shadow growing from lift to lift-raised (see Shadows).
The grid above is the live one, with the newest jam of each family. Hover a tile, or switch the covers off to see the tile colors and the duotone without them; with the covers off, the duotone tints the tile color instead of a grey image. The switches are plain checkboxes read by :has() (partials/cover-grid-demo.njk, local/cover-grid-demo.css); the Design System shows the same demo. A wiki page includes one with demo: in its front matter and the line <div data-demo></div> in its text.
The duotone ends come from the family’s tokens: the dark end is the bright token at 18% in black, the light end is the bright token itself. That variant (“Deep”) was picked from four on a local comparison page; the others mixed the light end with white or with the muted token, and came out lighter than the covers.
--cover-duo-dark: color-mix(in oklab, var(--cover-vivid) 18%, var(--color-base-black));
--cover-duo-light: var(--cover-vivid);The colors are palette values on purpose: the site has semantic tokens for blue and green (--color-accent-blue, --color-accent-green) but none for red or orange.
Picking the color family
Each post with a cover: has a coverColor: in its front matter: red, orange, green, blue or gray, the five families the site’s tokens offer. npm run covers:colors fills it in (src/_config/setup/cover-colors.js; add -- --write to save, --force to redo hand-set values):
- fetch the cover (through eleventy-fetch’s cache) and shrink it to 32 × 32 with sharp;
- convert each pixel to OKLCH;
- let each pixel with a chroma of at least 0.04 vote for the family whose reference hue is nearest, weighted by its chroma (reference hues are the vivid tokens’: red 27°, orange 48°, green 148°, blue 248°);
- call the cover gray if fewer than 8% of its pixels are colored, otherwise take the family with the most votes.
The first version used average chroma for the gray test and called half the covers gray; most of those were muted rather than colorless. Counting colored pixels lets a small accent name the hue, and leaves gray for genuinely black-and-white covers (41 of 140). The value is front matter rather than a build-time computation so it can be overridden by hand, and Sveltia has a “Cover color” select for it. A new post arrives without one and shows gray until the script is run.
Loading
An earlier version faded each tile from its color to the duotone and then to the cover, driven by a small script that marked tiles as their images loaded. It was dropped for a version with no script: the back button replayed the whole animation whenever the browser reloaded the page instead of restoring it, and the plain version, where each cover appears on its tile color as it loads, was preferred.
None of this is Eleventy Excellent stock.
Raw source: src/_raw/dev-notes/How the cover colors work.md




