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

  1. Run `hugo gen chromastyles --help` or consult `https://xyproto.github.io/splash/docs/` for the exact style ids your Hugo version supports.
  2. Fix the id form: use hyphenated lowercase ids like `solarized-dark`, `monokailight`, `github-dark` — not spaced display names.
  3. If the style was added in a newer Chroma, upgrade Hugo; if it was removed, pick the closest surviving style.
  4. Also check `markup.highlight.style` in hugo.toml, since the same validated name is used for site-wide highlighting.
  5. 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

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


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/f1e6d39e9e0f8918.json. Report an issue: GitHub ↗.