Colors
Theme-aware palette colours, your brand swatches and any exact hex, side by side.
Palette, swatches and hex#
textColor and backgroundColor hold one of three kinds of value, never a mix:
- A palette name:
gray, brown, red, orange, yellow, green, blue, purple, pink. These follow the theme, so red is lighter on a dark background. - A swatch name from
tools.colors.swatches, for brand colours. It renders as its hex in both themes. - Lowercase hex,
#rrggbb, plus#rrggbbaafor translucent backgrounds. It looks the same in both themes.
"default" means no colour. Anything else, such as rgb(…) or uppercase hex set through the API, is drawn as the default.
{ "type": "text", "text": "Palette", "styles": { "textColor": "red" } }
{ "type": "text", "text": "Exact", "styles": { "textColor": "#1f6feb", "backgroundColor": "#10b98140" } }
{ "type": "text", "text": "Brand", "styles": { "textColor": "brand" } }The color menu#
The toolbar's colour button has a Text and a Background section, each with:
- Default and the nine palette colours;
- your brand swatches;
- Document colors: up to eight hex colours already used in the document, most used first;
- Recent: the last eight custom colours, kept in
localStorage; - Custom…: a hex (or any CSS colour) field, the system colour picker, and an eyedropper in browsers that have the
EyeDropperAPI.
Hover a hex swatch to see its value.
Options#
<BlockEditor
tools={{
colors: {
palette: true, // the nine theme-aware colours (default)
custom: true, // document colours and Custom… (default)
swatches: [{ name: "brand", hex: "#ff5a1f" }],
},
}}
colorContrast="auto" // fix hex text that's hard to read on the current theme
/>palette: falsehides the palette and stops pasted colours snapping to it.custom: falsehides document colours and Custom…, and pasted hex that isn't close to a named colour goes to the palette colour for its hue.htmlMode="strict"does the same.- Swatch names are lowercase letters, digits and dashes, and can't be palette names. Invalid swatches are skipped.
Contrast
Hex colours don't adapt to the theme, so dark blue text can vanish in dark mode. colorContrast="auto" lightens or darkens hex text that has less than 3:1 contrast with the theme's background. Only the rendering changes; the stored colour and the exported HTML stay exact.
Pasted colours#
- Any CSS colour is read: names,
rgb(),hsl(), and 3-, 4-, 6- or 8-digit hex. Transparent colours,inheritandcurrentColorare dropped. - A colour within ΔE2000 3 of a palette colour or swatch becomes that name, so it follows the theme from then on.
- Near-black text (
#000,#1f1f1f,#333…), white backgrounds, and the blue sites use for links count as the default. - Everything else stays exact hex.
The import report counts pasted colours as colors.palette and colors.hex.
HTML#
Every colour is written as an inline style, so email clients and RSS readers show it. Names also get a data- attribute, so they read back as the name:
<span style="color:#e03e3e" data-text-color="red">Palette</span>
<span style="color:#1f6feb;background-color:#10b98140">Exact</span>
<span style="color:#ff5a1f" data-text-color="brand">Brand</span>toHTML and parseHTML on the server; the editor's getHTML() already uses its own.import { toHTML, parseHTML } from "genesis-editor/parser";
const swatches = [{ name: "brand", hex: "#ff5a1f" }];
toHTML(blocks, { swatches }); // brand → its hex, plus data-text-color="brand"
parseHTML(html, { tools: { colors: { swatches } } }); // data-text-color="brand" → "brand"