mdbook-kanagawa-theme
mdbook-kanagawa-theme provides an interactive, blog‑like landing page and
a full visual theme override for the HTML renderer. It does not replace
mdBook’s HTML backend, but it does replace the default theme/css/chrome.css
with a Kanagawa‑inspired variant. You can easily swap in any colorscheme you
like, with Dracula, Tokyo Night, and Catppuccin-Mocha example palettes included.
By tweaking per‑chapter frontmatter date, you can choose which pages are featured on the landing (for example, as “Latest Posts” or “Recent Notes”). Your book's structure stays the same, only your landing page is replaced. (This also works with no date listed by using timestamps).
mdBook's build-in theme selector still works, but each base theme is re-skinned with Kanagawa variables.
The landing page replaces index.md with a configurable side‑by‑side or
top-over-bottom layout:

Live Demo / Showcase



- Latest Posts
- Recent Notes
- Popular Tags
The content comes from:
Together they generate content-collections.json and expose a
window.CONTENT_COLLECTIONS global that this theme uses to render the cards.
You can click on the tag to bring up the associated chapters.



Installation
This section assumes that you already have mdbook installed.
# Install the themes dependencies
# You'll probably want to strip the frontmatter
# cargo install mdbook-frontmatter-strip
Version check:
Add the preprocessor to your book.toml. (I've included the other dependencies
for clarity, you'll still want to set your site-url and whatever else your
site requires):
[]
= "My Kanagawa Book"
= ["Your Name"]
= "Docs with a configurable Kanagawa-inspired landing page"
[]
# Optional, just to keep builds tidy
= "book"
[]
= ["html"]
[]
= "mdbook-content-loader"
= ["html"]
= ["content-collections"]
# inject_all = true
[]
= ["html"]
= ["content-loader", "content-collections"]
# Landing page text
= "My Docs"
= "Notes, posts, and more"
# Column headers
= "Latest posts"
= "Recent notes"
= "Popular tags"
# Use bigger cards and top-over-bottom layout in full-screen view
# card_layout = "wide" # or "compact" # side-by-side layout
# Optional: prepend an @import to the generated theme/css/chrome.css
# Path is relative to the built book root (same as other mdBook theme files).
# css_import = "/assets/dracula.css"
# css_import = "/assets/tokyo-night.css"
# css_import = "/assets/catppuccin-mocha.css"
# Optional: if true, the preprocessor will NOT write theme/css/chrome.css
# (use this if you want to maintain your own chrome.css instead)
# disable_builtin_css = true
# Optional: prepend an @import to the code theme CSS
# code_css_import = "theme/custom-code.css"
# Optional: support mdbook-kanagawa-theme in footer
# support_footer = true # Displays "Made with mdbook-kanagawa-theme" in footer and links to the repo
# Optionally override to a different link
# support_footer_href = "https://github.com/wolfpack1/bigDog's-project"
# support_footer_text = "Made in the U.S.A."
[]
# Do NOT use additional-css for the main theme override.
# default-theme still controls which theme class is set (rust, coal, navy, …)
# Kanagawa overrides the "navy" pallette specifically
= "navy"
= "navy"
# Also add kanagawa syntax highlightiing to the code blocks
= ["theme/css/kanagawa-code.css"]
You can change the header names to whatever you prefer.
On each build, the preprocessor:
-
Overwrites
index.mdwith the Kanagawa landing page HTML. -
Writes
theme/css/chrome.css, built from a template copy of mdBook’s ownchrome.cssplus Kanagawa variables and extra styles.
You do not need additional-css = ["theme/kanagawa.css"]; the theme is
injected by replacing theme/css/chrome.css directly. This was required for the
theme to be respected in the latest mdbook versions.
The additional-css shown above is strictly for the code block syntax
highlighting and is completely optional.
This only changes the cards width on bigger screens, the look is the same for phones:

Usage
The theme can use a blank or titled index.md for the landing page, you can
create one by adding the following to your SUMMARY.md as the first line:
[](index.md)
Or
[Introduction](index.md)
Kanagawa syntax highlighting (optional)
In addition to the main Kanagawa UI theme, the preprocessor can also generate a matching code theme for fenced code blocks. When enabled, it writes:
theme/css/chrome.css– the Kanagawa layout and UI chrome (as before)theme/css/kanagawa-code.css– Kanagawa-flavored syntax highlighting targeting mdBook’s defaulthighlight.jsclasses (such as.hljs,.hljs-keyword,.hljs-string,.hljs-comment, etc.)
To apply the code theme, add it to your HTML output configuration:
[]
= ["theme/css/kanagawa-code.css"]
chrome.css is still injected automatically by the preprocessor; only the code
theme needs to be listed in additional-css.
Frontmatter
- Adding the
dateis strongly recommended but not necessary, entries with nodatefall back to timestamps.
Latest posts
The "Latest posts" card is tied to the blog collection.
This theme works by filtering and sorting your frontmatter. For example, to add links/overviews/pics to the "Latest posts" card, your frontmatter would look like this:
---
title: Nix Pull Requests
date:
author: saylesss88
collection: "blog"
tags:
draft: false
---
Now the chapter with the above frontmatter will be added to the "Latest posts" card.
If you place an image above the first header, it will be shown in this card along with the date and overview. I may add the author to each chapter shown in "Latest posts" in the future but currently the author isn't listed.
Recent notes
The "Recent notes" card is tied to the notes collection:
---
title: Intro to Derivations
date:
author: saylesss88
collection: "notes"
tags:
---
Now this chapter will be added to the "Recent notes" card. This card only lists
the links rather than the complete overview like "Latest posts" does. The
frontmatter is fairly forgiving but in this case, "notes" must be quoted.
Popular tags
Popular tags is automatically populated from the tags key in the frontmatter.
You can click the tag to bring up the overviews of the chapters associated with the said tag.
Run mdbook build, and the theme is automatically injected and applied.
Overriding the palette (Dracula, Tokyo-Night, etc.)
Dracula is just an example, the idea is to allow overriding to whatever you
prefer, just change the values in the provided dracula.css to what you like.
You can still override the color palette while keeping the Kanagawa layout.
Create your-book/src/assets/dracula.css:
/* src/assets/dracula.css */
}
}
When you run mdbook build this file will be placed in
your-book/book/assets/dracula.css.
This only overrides the coal color-scheme from the dropdown. The other themes will still use the Kanagawa defaults.
Also override the code blocks with dracula syntax highlighting, create a
your-book/theme/css/dracula-code.css:
/* theme/css/dracula-code.css */
/* Base code block look: distinct but still Dracula */
}
}
/* Tokens */
}
}
}
}
}
/* Block code only */
}
/* Optional: make inline highlighted code look normal */
}
And in book.toml:
[]
= ["html"]
= ["content-loader", "content-collections"]
= "My mdBook"
= "Notes, posts, and more"
# These strings can be changed to whatever you prefer
= "Latest posts"
= "Recent notes"
= "Popular tags"
= "/assets/dracula.css"
= false
[]
# automatically switch to the override
= "coal"
= ["kanagawa-code.css", "dracula-code.css"]
With this setup:
-
mdBook still builds the book as usual, and
mdbook-kanagawa-themegeneratestheme/css/chrome.csswith the Kanagawa layout and variable hooks. -
The preprocessor adds an
@import "/assets/dracula.css";(fromcss_import) at the top of that generatedchrome.css, so your Dracula file runs after the built‑in variable defaults. -
Because
dracula.cssredefines the same CSS custom properties used by the Kanagawa theme (--bg,--fg,--accent, sidebar colors, etc.), the page keeps the Kanagawa layout and landing page, but all colors for thecoaltheme class come from your Dracula palette instead. Kanagawa provides the layout and default palette. -
The dracula theme only overrides the
coaltheme from the dropdown, this way you can easily switch between the normal themes with dracula and kanagawa added.

Tokyo-Night
Create your-book/src/assets/tokyo-night.css:
/* src/assets/tokyo-night.css */
}
/* Make code blocks use the dedicated code background on coal theme */
}
Add tokyo-night code block syntax highlighting, create a
your-book/theme/css/tokyo-night-code.css:
/* theme/css/tokyo-night-code.css */
/* Base code block look: a bit lighter than page bg */
}
}
/* Token colors */
}
}
}
}
}
/* Block code only */
}
/* Optional: make inline highlighted code look normal */
}
Add this to your book.toml along with what's been shown so far. The overrides
only apply to the coal theme from the dropdown:
= "/assets/tokyo-night.css"
= false
[]
# automatically switch to the override
= "coal"
= ["kanagawa-code.css", "tokyo-night-code.css"]
- The other themes will still use the Kanagawa defaults.

Catppuccin Mocha
Create your-book/src/assets/catppuccin-mocha.css
/* src/assets/catppuccin-mocha.css */
}
}
Add this to your book.toml along with what's been shown so far. The overrides
only apply to the coal theme from the dropdown:
Also apply catppuccin-mocha syntax highlighting for code blocks:
Create your-book/theme/css/catppuccin-mocha-code.css:
/* theme/css/catppuccin-mocha-code.css */
/* Base code block look: a bit lighter than page bg */
}
}
/* Tokens */
}
}
}
}
}
/* Block code only */
}
/* Optional: make inline highlighted code look normal */
}
= "/assets/catppuccin-mocha.css"
= false
[]
# automatically switch to the override
= "coal"
= [
"theme/css/kanagawa-code.css",
"theme/css/catppuccin-mocha-code.css",
]
-
"theme/css/kanagawa-code.css"isn't required. -
The other themes continue to use the Kanagawa palette.

Light/Dark and default-theme behavior
Because this crate replaces theme/css/chrome.css, it effectively owns the
visual theme for all built‑in modes (light, rust, coal, navy). The
mdBook theme dropdown and your default-theme / preferred-dark-theme still
control which class is applied to the page, but the palette for each of those
classes is defined by the Kanagawa (or Dracula/Tokyo-Night/Catppuccin
overridden) variables.
Stripping the Frontmatter
mdBook does not parse or strip YAML frontmatter, so the raw block (e.g. any YAML
keys like title:, date:, etc.) appears in the HTML.
To avoid this, you can use: