Featured image of post Customize Hugo PaperMod Colors with CSS Variables

Customize Hugo PaperMod Colors with CSS Variables

Override PaperMod color variables for light and dark themes with extended CSS, then check text contrast.

PaperMod colors can be customized with CSS custom properties (variables). Put overrides in your site’s assets/css/extended/ directory rather than editing theme files, so they are easier to keep across theme updates. The example below defines a warm light palette and a dark palette; adjust the values for your site.

Dark mode and current variables

Current PaperMod switches dark mode by setting data-theme="dark" on the html element. Older examples that target only .dark may not match this theme selector. --hljs-bg is also not the current variable for the code-block background; the current name is --code-block-bg.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* Save as assets/css/extended/theme-colors.css */
:root {
    color-scheme: light;
    --theme: #fbf7ef;
    --entry: #fffdfa;
    --primary: #433a32;
    --secondary: #665b50;
    --tertiary: #8b7f72;
    --content: #453d35;
    --code-block-bg: #34231b;
    --code-bg: #efe7da;
    --border: #ddd3c5;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --theme: #1d1e20;
    --entry: #22252a;
    --primary: #e8e6e1;
    --secondary: #b5b2ac;
    --tertiary: #55575c;
    --content: #d2d0ca;
    --code-block-bg: #17181a;
    --code-bg: #37383e;
    --border: #48484c;
}

Text contrast

In this example, the normal text colors --primary and --content contrast strongly with their backgrounds. The sample contrast for --primary against --theme is about 10.4:1 in light mode and 13.4:1 in dark mode. WCAG 2.2 AA requires 4.5:1 for normal text, but check syntax colors, links, borders, and other states separately.

Add and check extended CSS

Save the stylesheet as assets/css/extended/theme-colors.css at your site root. PaperMod’s FAQ says CSS files in assets/css/extended/ are bundled with the theme styles. Run Hugo and check the light/dark switch, cards, body text, inline code, code blocks, and links.

Scope

This is an illustrative palette; it does not guarantee accessibility conformance for every text string, image, or interactive component. Syntax-highlight colors are defined separately from --code-block-bg, so recheck code readability after changing the block background.

References

Licensed under CC BY-NC-SA 4.0
Last updated on 2026/11/24 00:00 +0900
comments powered by Disqus