Skip to content

Instantly share code, notes, and snippets.

@sspaeti
Last active February 18, 2026 09:12
Show Gist options
  • Select an option

  • Save sspaeti/1856cf717357f54e07f989884368d994 to your computer and use it in GitHub Desktop.

Select an option

Save sspaeti/1856cf717357f54e07f989884368d994 to your computer and use it in GitHub Desktop.
Custom Themes for mdBook in `theme/css/variables.css`
/* Globals */
:root {
--sidebar-target-width: 300px;
--sidebar-width: min(var(--sidebar-target-width), 80vw);
--sidebar-resize-indicator-width: 8px;
--sidebar-resize-indicator-space: 2px;
--page-padding: 15px;
--content-max-width: 750px;
--menu-bar-height: 50px;
--mono-font: 'Iosevka Web', 'Iosevka', 'Source Code Pro', 'Fira Code', 'Fira Code', 'Open Sans', 'Consolas', "Ubuntu Mono", 'Menlo', 'DejaVu Sans Mono';
--code-font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */
--searchbar-margin-block-start: 5px;
/* Customized by sspaeti: default fonts */
--font-body: 'Atkinson Hyperlegible', 'Piazzolla, serif;', 'Open Sans', sans-serif, system-ui, -apple-system, BlinkMacSystemFont, PingFang SC, Microsoft YaHei UI, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, Helvetica, Arial;
}
/* CUSTOMIZED sspaeti: Themes */
/* My favorite theme: https://github.com/rebelot/kanagawa.nvim */
.kanagawa {
/* Using the Kanagawa color palette */
--bg: #1F1F28; /* sumiInk1 for Default background */
--fg: #DCD7BA; /* fujiWhite for Default foreground */
--sidebar-bg: #2A2A37; /* sumiInk2 for a subtler sidebar background */
--sidebar-fg: #C8C093; /* oldWhite for Dark foreground in sidebar */
/* Other color assignments based on the palette */
--sidebar-non-existant: #54546D; /* sumiInk4 */
--sidebar-active: #FF9E3B; /* roninYellow for Diagnostic Warning */
--sidebar-spacer: #363646; /* sumiInk3 */
--scrollbar: var(--sidebar-fg);
--icons: #7E9CD8; /* #98BB6C; springGreen for Strings */
--icons: #54546D; /* sumiInk4 for Darker foreground */
--icons-hover: #7E9CD8; /* crystalBlue for Functions and Titles */
--links: #7FB4CA; /* springBlue for Specials and builtin functions */
--inline-code-color: #E82424; /* samuraiRed for Diagnostic Error */
--theme-popup-bg: #223249; /* waveBlue1 for Popup background */
--theme-popup-border: #2D4F67; /* waveBlue2 for Popup selection background */
--theme-hover: #16161D; /* sumiInk0 for Dark background */
--quote-bg: #252535; /* winterBlue for Diff Line background */
--quote-border: #2B3328; /* winterGreen for Diff Add background */
--table-border-color: #49443C; /* winterYellow for Diff Change background */
--table-header-bg: #43242B; /* winterRed for Diff Deleted background */
--table-alternate-bg: #1F1F28; /* sumiInk1 */
--searchbar-border-color: #658594; /* dragonBlue for Diagnostic Hint */
--searchbar-bg: #6A9589; /* waveAqua1 for Diagnostic Info */
--searchbar-fg: #fff;
--searchbar-shadow-color: #d4c89f;
--searchresults-header-fg: #666;
--searchresults-border-color: #888;
--searchresults-li-bg: #2A2A37; /* sumiInk2 */
--search-mark-bg: #E6C384; /* carpYellow for Identifiers */
--color-scheme: dark;
--copy-button-filter: invert(45%) sepia(6%) saturate(621%) hue-rotate(198deg) brightness(99%) contrast(85%);
--copy-button-filter-hover: invert(68%) sepia(55%) saturate(531%) hue-rotate(341deg) brightness(104%) contrast(101%);
--footnote-highlight: #7E9CD8; /* crystalBlue */
--overlay-bg: rgba(31, 31, 40, 0.4);
--blockquote-note-color: #7FB4CA;
--blockquote-tip-color: #98BB6C;
--blockquote-important-color: #957FB8;
--blockquote-warning-color: #FF9E3B;
--blockquote-caution-color: #E82424;
--sidebar-header-border-color: #FF9E3B;
}
/* Override code blocks for Kanagawa theme */
.kanagawa .hljs {
background: #2A2A37; /* sumiInk2 for a slightly lighter background */
color: #DCD7BA; /* fujiWhite for Default foreground */
}
.kanagawa .hljs-section {
color: #7E9CD8; /* crystalBlue for Functions and Titles */
}
/* added a pink color theme: my daughter asked!
* https://github.com/rose-pine/neovim
*/
.pinkrose {
/* Base and Surface colors for background and foreground */
--bg: #1f1d2e; /* Surface color */
--fg: #e0def4; /* Text color */
/* Subtler sidebar to keep focus on the content */
--sidebar-bg: #191724; /* Base color */
--sidebar-fg: #908caa; /* Subtle color */
/* Additional color assignments from the palette */
--sidebar-non-existant: #524f67; /* Highlight High */
--sidebar-active: #eb6f92; /* Love */
--sidebar-spacer: #403d52; /* Highlight Med */
--scrollbar: var(--sidebar-fg);
--icons: #31748f; /* Pine */
--icons-hover: #c4a7e7; /* Iris */
--links: #f6c177; /* Gold */
--inline-code-color: #ebbcba; /* Rose */
--theme-popup-bg: #26233a; /* Overlay */
--theme-popup-border: #6e6a86; /* Muted */
--theme-hover: #21202e; /* Highlight Low */
--quote-bg: #26233a; /* Overlay */
--quote-border: #403d52; /* Highlight Med */
--table-border-color: #524f67; /* Highlight High */
--table-header-bg: #403d52; /* Highlight Med */
--table-alternate-bg: #1f1d2e; /* Surface */
--searchbar-border-color: #6e6a86; /* Muted */
--searchbar-bg: #26233a; /* Overlay */
--searchbar-fg: #e0def4; /* Text */
--searchbar-shadow-color: #eb6f92; /* Love */
--searchresults-header-fg: #908caa; /* Subtle */
--searchresults-border-color: #524f67; /* Highlight High */
--searchresults-li-bg: #1f1d2e; /* Surface */
--search-mark-bg: #f6c177; /* Gold */
--color-scheme: dark;
--copy-button-filter: invert(26%) sepia(8%) saturate(575%) hue-rotate(169deg) brightness(87%) contrast(82%);
--copy-button-filter-hover: invert(50%) sepia(50%) saturate(700%) hue-rotate(310deg) brightness(95%) contrast(95%);
--footnote-highlight: #c4a7e7; /* Iris */
--overlay-bg: rgba(25, 23, 36, 0.4);
--blockquote-note-color: #9ccfd8;
--blockquote-tip-color: #31748f;
--blockquote-important-color: #c4a7e7;
--blockquote-warning-color: #f6c177;
--blockquote-caution-color: #eb6f92;
--sidebar-header-border-color: #eb6f92;
}
/* Override Code Blocks for Rose Pink theme */
.pinkrose .hljs {
background: #ffe4e1; /* Light pink background for contrast */
color: #d26a7e; /* Darker rose color for text */
}
.pinkrose .hljs-section {
color: #b23a48; /* Rich rose color for section titles */
}
/* This is made with love for my older daugher <3 */
.tokyonight {
/* Tokyo Night color palette with more purple */
--bg: #202330; /* A darker background for main content */
--fg: #959cbd; /* Foreground color with a purple hue */
--sidebar-bg: #1B2232; /* Slightly lighter than --bg for the sidebar */
--sidebar-fg: #bdc7f0; /* Foreground color for the sidebar */
/* Enhancing link colors */
--links: #7a82da; /* More vibrant purple for links */
--links-hover: #a0a8e6; /* Lighter purple for hover state */
--sidebar-link-hover: #a0a8e6; /* Hover color for sidebar links */
/* Other color assignments based on the palette */
--sidebar-non-existant: #696d87; /* GitDecoration ignoredResourceForeground */
--sidebar-active: #7a82da; /* More vibrant purple for active elements */
--sidebar-spacer: #787c99; /* Inactive elements in activityBar */
--scrollbar: var(--sidebar-fg);
--icons: #959cbd; /* General icon color */
--icons-hover: #3d59a1; /* panelTitle activeBorder color for hover state */
--inline-code-color: #bdc7f0; /* Foreground color for inline code */
--theme-popup-bg: #1B2232; /* Similar to sidebar background */
--theme-popup-border: #787c99; /* Inactive elements in activityBar */
--theme-hover: #202330; /* Background color for hover states */
--quote-bg: #1B2232; /* Sidebar background for consistency */
--quote-border: #787c99; /* Inactive elements in activityBar */
--table-border-color: #1B2232; /* Sidebar background for consistency */
--table-header-bg: #202330; /* Main background color */
--table-alternate-bg: #1B2232; /* Sidebar background for alternate rows */
--searchbar-border-color: #787c99; /* Inactive elements in activityBar */
--searchbar-bg: #202330; /* Main background color */
--searchbar-fg: #bdc7f0; /* Foreground color */
--searchbar-shadow-color: #3d59a1; /* panelTitle activeBorder color */
--searchresults-header-fg: #959cbd; /* General foreground color */
--searchresults-border-color: #787c99; /* Inactive elements in activityBar */
--searchresults-li-bg: #1B2232; /* Sidebar background for list items */
--search-mark-bg: #bdc7f0; /* Foreground color for search highlights */
--color-scheme: dark;
--copy-button-filter: invert(51%) sepia(10%) saturate(393%) hue-rotate(198deg) brightness(86%) contrast(87%);
--copy-button-filter-hover: invert(46%) sepia(20%) saturate(1537%) hue-rotate(156deg) brightness(85%) contrast(90%);
--footnote-highlight: #7a82da;
--overlay-bg: rgba(27, 34, 50, 0.4);
--blockquote-note-color: #7dcfff;
--blockquote-tip-color: #9ece6a;
--blockquote-important-color: #bb9af7;
--blockquote-warning-color: #e0af68;
--blockquote-caution-color: #f7768e;
--sidebar-header-border-color: #7a82da;
}
/* Override Code Blocks for Tokyo Night theme */
.tokyonight .hljs {
background: #1B2232; /* A darker background, similar to sidebar-bg */
color: #bdc7f0; /* Foreground color used in sidebar */
}
.tokyonight .hljs-section {
color: #7a82da; /* More vibrant purple for titles and sections */
}
/* This is made with love for my wife, who was eager to have one after the kids both had one ;) */
.burgundy {
/* Set a unique base for the theme with a Burgundy accent */
--bg: #FFF8F0; /* Creamy white for a unique background */
--fg: #352839; /* Burgundy for primary text, making it the featured color */
/* Sidebar with a distinctive look and Burgundy highlights */
--sidebar-bg: #352839; /* Soft pinkish-white for sidebar background */
--sidebar-fg: #FFF0F8; /* Burgundy for sidebar text */
--sidebar-non-existant: #E8D8E0; /* Soft lavender for non-existent items */
--sidebar-active: #DAA6B1; /* A softer, lighter shade of Burgundy */
--sidebar-spacer: #FFFAFA; /* Very light pink for sidebar spacer */
--scrollbar: #B8A8B0; /* Muted lavender for scrollbar */
/* Icons and links with Burgundy as the key accent color */
--icons: #A08088; /* Soft brownish-pink for icons */
--icons-hover: #352839; /* Burgundy for hovered icons */
--links: #352839; /* Burgundy for links */
--inline-code-color: #352839; /* Burgundy for inline code */
/* Popups and quotes with a unique and gentle appearance */
--theme-popup-bg: #FFF8F0; /* Creamy white for popup background */
--theme-popup-border: #E0C0C8; /* Light rosy for popup borders */
--theme-hover: #FFF0F8; /* Soft pinkish-white for hover background */
--quote-bg: #FFF0F0; /* Very light pink for quote background */
--quote-border: #F0D0D8; /* Light pink for quote border */
/* Tables with a touch of Burgundy and complementary colors */
--table-border-color: #E8D0D8; /* Light rosy for table borders */
--table-header-bg: #FFF0F8; /* Soft pinkish-white for table header background */
--table-alternate-bg: #FFF8F0; /* Creamy white for alternate rows */
/* Search bar and results with a blend of theme colors */
--searchbar-border-color: #D8C0C8; /* Light rosy for search bar border */
--searchbar-bg: #FFF8F0; /* Creamy white for search bar background */
--searchbar-fg: #352839; /* Burgundy for search bar text */
--searchbar-shadow-color: #E0C0C8; /* Light rosy for search bar shadow */
--searchresults-header-fg: #A08088; /* Soft brownish-pink for search results header */
--searchresults-border-color: #C8B0B8; /* Muted pink for search results border */
--searchresults-li-bg: #FFF0F8; /* Soft pinkish-white for search results list item background */
--search-mark-bg: #FFE0E0; /* Very light pink for search mark background */
--color-scheme: light;
--copy-button-filter: invert(45.49%);
--copy-button-filter-hover: invert(14%) sepia(93%) saturate(4250%) hue-rotate(243deg) brightness(99%) contrast(130%);
--footnote-highlight: #DAA6B1;
--overlay-bg: rgba(200, 200, 205, 0.4);
--blockquote-note-color: #0969da;
--blockquote-tip-color: #008000;
--blockquote-important-color: #8250df;
--blockquote-warning-color: #9a6700;
--blockquote-caution-color: #b52731;
--sidebar-header-border-color: #DAA6B1;
}
.burgundy .hljs {
background: #FFF0F8; /* A soft pinkish-white, in line with the theme */
color: #352839; /* Burgundy for the code text, ensuring readability */
}
.burgundy .hljs-section {
color: #A08088; /* A soft brownish-pink, for syntax highlighting */
}
/* default: Themes */
.ayu {
--bg: hsl(210, 25%, 8%);
--fg: #c5c5c5;
--sidebar-bg: #14191f;
--sidebar-fg: #c8c9db;
--sidebar-non-existant: #5c6773;
--sidebar-active: #ffb454;
--sidebar-spacer: #2d334f;
--scrollbar: var(--sidebar-fg);
--icons: #737480;
--icons-hover: #b7b9cc;
--links: #0096cf;
--inline-code-color: #ffb454;
--theme-popup-bg: #14191f;
--theme-popup-border: #5c6773;
--theme-hover: #191f26;
--quote-bg: hsl(226, 15%, 17%);
--quote-border: hsl(226, 15%, 22%);
--warning-border: #ff8e00;
--table-border-color: hsl(210, 25%, 13%);
--table-header-bg: hsl(210, 25%, 28%);
--table-alternate-bg: hsl(210, 25%, 11%);
--searchbar-border-color: #848484;
--searchbar-bg: #424242;
--searchbar-fg: #fff;
--searchbar-shadow-color: #d4c89f;
--searchresults-header-fg: #666;
--searchresults-border-color: #888;
--searchresults-li-bg: #252932;
--search-mark-bg: #e3b171;
--color-scheme: dark;
--copy-button-filter: invert(45%) sepia(6%) saturate(621%) hue-rotate(198deg) brightness(99%) contrast(85%);
--copy-button-filter-hover: invert(68%) sepia(55%) saturate(531%) hue-rotate(341deg) brightness(104%) contrast(101%);
--footnote-highlight: #2668a6;
--overlay-bg: rgba(33, 40, 48, 0.4);
--blockquote-note-color: #74b9ff;
--blockquote-tip-color: #09ca09;
--blockquote-important-color: #d3abff;
--blockquote-warning-color: #f0b72f;
--blockquote-caution-color: #f21424;
--sidebar-header-border-color: #c18639;
}
.coal {
--bg: hsl(200, 7%, 8%);
--fg: #98a3ad;
--sidebar-bg: #292c2f;
--sidebar-fg: #a1adb8;
--sidebar-non-existant: #505254;
--sidebar-active: #3473ad;
--sidebar-spacer: #393939;
--scrollbar: var(--sidebar-fg);
--icons: #43484d;
--icons-hover: #b3c0cc;
--links: #2b79a2;
--inline-code-color: #c5c8c6;
--theme-popup-bg: #141617;
--theme-popup-border: #43484d;
--theme-hover: #1f2124;
--quote-bg: hsl(234, 21%, 18%);
--quote-border: hsl(234, 21%, 23%);
--warning-border: #ff8e00;
--table-border-color: hsl(200, 7%, 13%);
--table-header-bg: hsl(200, 7%, 28%);
--table-alternate-bg: hsl(200, 7%, 11%);
--searchbar-border-color: #aaa;
--searchbar-bg: #b7b7b7;
--searchbar-fg: #000;
--searchbar-shadow-color: #aaa;
--searchresults-header-fg: #666;
--searchresults-border-color: #98a3ad;
--searchresults-li-bg: #2b2b2f;
--search-mark-bg: #355c7d;
--color-scheme: dark;
--copy-button-filter: invert(26%) sepia(8%) saturate(575%) hue-rotate(169deg) brightness(87%) contrast(82%);
--copy-button-filter-hover: invert(36%) sepia(70%) saturate(503%) hue-rotate(167deg) brightness(98%) contrast(89%);
--footnote-highlight: #4079ae;
--overlay-bg: rgba(33, 40, 48, 0.4);
--blockquote-note-color: #4493f8;
--blockquote-tip-color: #08ae08;
--blockquote-important-color: #ab7df8;
--blockquote-warning-color: #d29922;
--blockquote-caution-color: #d91b29;
--sidebar-header-border-color: #3473ad;
}
.light, html:not(.js) {
--bg: hsl(0, 0%, 100%);
--fg: hsl(0, 0%, 0%);
--sidebar-bg: #fafafa;
--sidebar-fg: hsl(0, 0%, 0%);
--sidebar-non-existant: #aaaaaa;
--sidebar-active: #1f1fff;
--sidebar-spacer: #f4f4f4;
--scrollbar: #8F8F8F;
--icons: #747474;
--icons-hover: #000000;
--links: #20609f;
--inline-code-color: #301900;
--theme-popup-bg: #fafafa;
--theme-popup-border: #cccccc;
--theme-hover: #e6e6e6;
--quote-bg: hsl(197, 37%, 96%);
--quote-border: hsl(197, 37%, 91%);
--warning-border: #ff8e00;
--table-border-color: hsl(0, 0%, 95%);
--table-header-bg: hsl(0, 0%, 80%);
--table-alternate-bg: hsl(0, 0%, 97%);
--searchbar-border-color: #aaa;
--searchbar-bg: #fafafa;
--searchbar-fg: #000;
--searchbar-shadow-color: #aaa;
--searchresults-header-fg: #666;
--searchresults-border-color: #888;
--searchresults-li-bg: #e4f2fe;
--search-mark-bg: #a2cff5;
--color-scheme: light;
--copy-button-filter: invert(45.49%);
--copy-button-filter-hover: invert(14%) sepia(93%) saturate(4250%) hue-rotate(243deg) brightness(99%) contrast(130%);
--footnote-highlight: #7e7eff;
--overlay-bg: rgba(200, 200, 205, 0.4);
--blockquote-note-color: #0969da;
--blockquote-tip-color: #008000;
--blockquote-important-color: #8250df;
--blockquote-warning-color: #9a6700;
--blockquote-caution-color: #b52731;
--sidebar-header-border-color: #6e6edb;
}
.navy {
--bg: hsl(226, 23%, 11%);
--fg: #bcbdd0;
--sidebar-bg: #282d3f;
--sidebar-fg: #c8c9db;
--sidebar-non-existant: #505274;
--sidebar-active: #2b79a2;
--sidebar-spacer: #2d334f;
--scrollbar: var(--sidebar-fg);
--icons: #737480;
--icons-hover: #b7b9cc;
--links: #2b79a2;
--inline-code-color: #c5c8c6;
--theme-popup-bg: #161923;
--theme-popup-border: #737480;
--theme-hover: #282e40;
--quote-bg: hsl(226, 15%, 17%);
--quote-border: hsl(226, 15%, 22%);
--warning-border: #ff8e00;
--table-border-color: hsl(226, 23%, 16%);
--table-header-bg: hsl(226, 23%, 31%);
--table-alternate-bg: hsl(226, 23%, 14%);
--searchbar-border-color: #aaa;
--searchbar-bg: #aeaec6;
--searchbar-fg: #000;
--searchbar-shadow-color: #aaa;
--searchresults-header-fg: #5f5f71;
--searchresults-border-color: #5c5c68;
--searchresults-li-bg: #242430;
--search-mark-bg: #a2cff5;
--color-scheme: dark;
--copy-button-filter: invert(51%) sepia(10%) saturate(393%) hue-rotate(198deg) brightness(86%) contrast(87%);
--copy-button-filter-hover: invert(46%) sepia(20%) saturate(1537%) hue-rotate(156deg) brightness(85%) contrast(90%);
--footnote-highlight: #4079ae;
--overlay-bg: rgba(33, 40, 48, 0.4);
--blockquote-note-color: #4493f8;
--blockquote-tip-color: #09ca09;
--blockquote-important-color: #ab7df8;
--blockquote-warning-color: #d29922;
--blockquote-caution-color: #f21424;
--sidebar-header-border-color: #2f6ab5;
}
.rust {
--bg: hsl(60, 9%, 87%);
--fg: #262625;
--sidebar-bg: #3b2e2a;
--sidebar-fg: #c8c9db;
--sidebar-non-existant: #505254;
--sidebar-active: #e69f67;
--sidebar-spacer: #45373a;
--scrollbar: var(--sidebar-fg);
--icons: #737480;
--icons-hover: #262625;
--links: #2b79a2;
--inline-code-color: #6e6b5e;
--theme-popup-bg: #e1e1db;
--theme-popup-border: #b38f6b;
--theme-hover: #99908a;
--quote-bg: hsl(60, 5%, 75%);
--quote-border: hsl(60, 5%, 70%);
--warning-border: #ff8e00;
--table-border-color: hsl(60, 9%, 82%);
--table-header-bg: #b3a497;
--table-alternate-bg: hsl(60, 9%, 84%);
--searchbar-border-color: #aaa;
--searchbar-bg: #fafafa;
--searchbar-fg: #000;
--searchbar-shadow-color: #aaa;
--searchresults-header-fg: #666;
--searchresults-border-color: #888;
--searchresults-li-bg: #dec2a2;
--search-mark-bg: #e69f67;
--color-scheme: light;
--copy-button-filter: invert(51%) sepia(10%) saturate(393%) hue-rotate(198deg) brightness(86%) contrast(87%);
--copy-button-filter-hover: invert(77%) sepia(16%) saturate(1798%) hue-rotate(328deg) brightness(98%) contrast(83%);
--footnote-highlight: #d3a17a;
--overlay-bg: rgba(150, 150, 150, 0.25);
--blockquote-note-color: #023b95;
--blockquote-tip-color: #007700;
--blockquote-important-color: #8250df;
--blockquote-warning-color: #603700;
--blockquote-caution-color: #aa1721;
--sidebar-header-border-color: #8c391f;
}
@media (prefers-color-scheme: dark) {
html:not(.js) {
--bg: hsl(200, 7%, 8%);
--fg: #98a3ad;
--sidebar-bg: #292c2f;
--sidebar-fg: #a1adb8;
--sidebar-non-existant: #505254;
--sidebar-active: #3473ad;
--sidebar-spacer: #393939;
--scrollbar: var(--sidebar-fg);
--icons: #43484d;
--icons-hover: #b3c0cc;
--links: #2b79a2;
--inline-code-color: #c5c8c6;
--theme-popup-bg: #141617;
--theme-popup-border: #43484d;
--theme-hover: #1f2124;
--quote-bg: hsl(234, 21%, 18%);
--quote-border: hsl(234, 21%, 23%);
--warning-border: #ff8e00;
--table-border-color: hsl(200, 7%, 13%);
--table-header-bg: hsl(200, 7%, 28%);
--table-alternate-bg: hsl(200, 7%, 11%);
--searchbar-border-color: #aaa;
--searchbar-bg: #b7b7b7;
--searchbar-fg: #000;
--searchbar-shadow-color: #aaa;
--searchresults-header-fg: #666;
--searchresults-border-color: #98a3ad;
--searchresults-li-bg: #2b2b2f;
--search-mark-bg: #355c7d;
--color-scheme: dark;
--copy-button-filter: invert(26%) sepia(8%) saturate(575%) hue-rotate(169deg) brightness(87%) contrast(82%);
--copy-button-filter-hover: invert(36%) sepia(70%) saturate(503%) hue-rotate(167deg) brightness(98%) contrast(89%);
--footnote-highlight: #4079ae;
--overlay-bg: rgba(33, 40, 48, 0.4);
--blockquote-note-color: #4493f8;
--blockquote-tip-color: #08ae08;
--blockquote-important-color: #ab7df8;
--blockquote-warning-color: #d29922;
--blockquote-caution-color: #d91b29;
--sidebar-header-border-color: #3473ad;
}
}
@sspaeti
Copy link
Author

sspaeti commented Feb 18, 2026

@SomeRanDev I just last week updated my mdBook to latest version. And the way it works, I just add the default theme of mdBook too (.ayu, .rust, etc) - so the list contains all -> see above I updated the Gist to my last version.

And I asked Claude to explain how it works - so here's the step by step documentation, that worked for me:

Adding Custom Themes to mdBook Without Losing Defaults

theme/css/variables.css is an all-or-nothing override. When mdBook sees this file in your theme/ directory, it replaces the built-in one entirely. You must include all default themes AND your custom ones in the same file.

Steps

1. Copy the default variables.css

mkdir -p theme/css
mdbook init --theme  # generates theme/ with defaults
# Keep theme/css/variables.css (and theme/index.hbs if adding theme picker buttons)

2. Append custom themes to theme/css/variables.css

Keep all built-in theme classes (.ayu, .coal, .light, .navy, .rust, plus the @media (prefers-color-scheme: dark) block), then add yours below:

/* ... all default themes (ayu, coal, light, navy, rust) stay above ... */

.kanagawa {
    --bg: #1F1F28;
    --fg: #DCD7BA;
    --sidebar-bg: #2A2A37;
    --sidebar-fg: #C8C093;
    /* define ALL the same CSS variables the defaults use */
    --color-scheme: dark;
}

/* Code block overrides for your theme */
.kanagawa .hljs {
    background: #2A2A37;
    color: #DCD7BA;
}

3. Add theme picker button in theme/index.hbs

Find the theme button list and add your entry. In mdBook v0.5.x, IDs use the mdbook-theme- prefix:

<li role="none"><button role="menuitem" class="theme" id="mdbook-theme-kanagawa">Kanagawa</button></li>

For mdBook v0.4.x, the ID has no prefix:

<li role="none"><button role="menuitem" class="theme" id="kanagawa">Kanagawa</button></li>

4. Reference in book.toml

[output.html]
default-theme = "light"
preferred-dark-theme = "kanagawa"

Why it breaks without this

The file replaces the default — it doesn't merge. If your variables.css only contains .kanagawa, all other themes (.light, .coal, etc.) disappear. You have to carry forward all built-in definitions yourself.

Real-world example

See my working book at dedp.online. It includes 4 custom themes (Kanagawa, Rose Pink, Tokyo Night, Burgundy) alongside all mdBook defaults.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment