gohugoio/hugo · error
invalid style: %s
Error message
invalid style: %s
What it means
`ChromaStylesCSS` in markup/highlight/chromastyles.go lowercases the requested style name and checks it against `styles.Names()` from the Chroma library. An unknown name returns this error rather than silently falling back, so a typo can't produce a stylesheet that looks wrong at runtime. Style lookup is case-insensitive but otherwise exact.
Source
Thrown at markup/highlight/chromastyles.go:56
// Foreground and background colors for highlighted lines, e.g. "#fff000 bg:#000fff".
HighlightStyle string
// Foreground and background colors for inline line numbers.
LineNumbersInlineStyle string
// Foreground and background colors for table line numbers.
LineNumbersTableStyle string
// Omit CSS class comment prefixes in the generated CSS.
OmitClassComments bool
}
// ChromaStylesCSS generates a CSS stylesheet for the Chroma code highlighter.
// This stylesheet is needed if markup.highlight.noClasses is disabled in config.
func ChromaStylesCSS(opts ChromaStylesOptions) (string, error) {
name := strings.ToLower(opts.Style)
if !slices.Contains(styles.Names(), name) {
return "", fmt.Errorf("invalid style: %s", name)
}
var chromaStyle *chroma.Style
if opts.Mode != "" {
var mode chroma.Mode
switch opts.Mode {
case "light":
mode = chroma.Light
case "dark":
mode = chroma.Dark
default:
return "", fmt.Errorf("invalid mode: %s", opts.Mode)
}
chromaStyle = styles.GetForMode(name, mode)
if chromaStyle.Mode() != mode {
return "", fmt.Errorf("style %q does not have a %q mode", name, opts.Mode)
}
} else {View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Run `hugo gen chromastyles --help` or consult `https://xyproto.github.io/splash/docs/` for the exact style ids your Hugo version supports.
- Fix the id form: use hyphenated lowercase ids like `solarized-dark`, `monokailight`, `github-dark` — not spaced display names.
- If the style was added in a newer Chroma, upgrade Hugo; if it was removed, pick the closest surviving style.
- Also check `markup.highlight.style` in hugo.toml, since the same validated name is used for site-wide highlighting.
- Note the separate `invalid mode` error just below: `--mode` accepts only `light` or `dark`.
Example fix
# before hugo gen chromastyles --style="solarized dark" > syntax.css # after hugo gen chromastyles --style=solarized-dark > syntax.css
Defensive patterns
Strategy: validation
Validate before calling
// verify the Chroma style name before setting markup.highlight.style
// CLI: hugo gen chromastyles --style=monokai (fails fast on invalid names)
valid := styles.Names() // github.com/alecthomas/chroma/v2/styles
if !slices.Contains(valid, styleName) {
return fmt.Errorf("invalid chroma style %q", styleName)
} Prevention
- Pick style names from the Chroma style gallery (e.g. monokai, dracula, github)
- Style names are lowercase and case-sensitive in config
- Validate markup.highlight.style in CI with hugo gen chromastyles --style=<name>
When it happens
Trigger: Calling `hugo gen chromastyles --style=<name>` or the `.Style` field of `ChromaStylesOptions` with a name Chroma doesn't ship — a typo, a Pygments-only theme name, or a style removed/renamed in the Chroma version vendored by your Hugo build.
Common situations: Copying a style name from Pygments docs that Chroma never implemented; using a display name with spaces (`solarized dark`) instead of the Chroma id (`solarized-dark`); upgrading or downgrading Hugo across a Chroma version bump that added or renamed styles; setting `markup.highlight.style` in hugo.toml to a name valid in a newer Hugo than the one building.
Related errors
- invalid mode: %s
- style %q does not have a %q mode
- language %q not found
- unsupported format: %q
- Unable to locate config file or config directory. Perhaps yo
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/f1e6d39e9e0f8918.json.
Report an issue: GitHub ↗.