<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Theme Stack on Daniel Zhang</title><link>https://zhangdapeng.dev/tags/theme-stack/</link><description>Recent content in Theme Stack on Daniel Zhang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sat, 07 Nov 2026 08:00:00 +0800</lastBuildDate><atom:link href="https://zhangdapeng.dev/tags/theme-stack/index.xml" rel="self" type="application/rss+xml"/><item><title>How to Make Hugo Code Highlighting Follow Dark and Light Theme Modes</title><link>https://zhangdapeng.dev/p/how-to-make-hugo-code-highlighting-follow-dark-and-light-theme-modes/</link><pubDate>Sat, 07 Nov 2026 08:00:00 +0800</pubDate><guid>https://zhangdapeng.dev/p/how-to-make-hugo-code-highlighting-follow-dark-and-light-theme-modes/</guid><description>&lt;img src="https://zhangdapeng.dev/p/how-to-make-hugo-code-highlighting-follow-dark-and-light-theme-modes/cover.png" alt="Featured image of post How to Make Hugo Code Highlighting Follow Dark and Light Theme Modes" /&gt;&lt;p&gt;When building a blog with Hugo, many modern themes, including &lt;code&gt;hugo-theme-stack&lt;/code&gt;, provide built-in Dark and Light mode switching.&lt;/p&gt;
&lt;p&gt;However, there is a common issue that can easily go unnoticed: &lt;strong&gt;the page theme changes, but the code blocks keep their original syntax highlighting colors.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For example, after switching to Dark Mode, the page background becomes dark, but code blocks still use a white background with light-theme syntax colors.&lt;/p&gt;
&lt;p&gt;This creates an inconsistent visual experience and can make code harder to read.&lt;/p&gt;
&lt;p&gt;In this article, I&amp;rsquo;ll show you how to solve this problem using Hugo&amp;rsquo;s built-in Chroma highlighting engine, two static CSS themes, and SCSS.&lt;/p&gt;
&lt;p&gt;The solution requires no additional JavaScript highlighting libraries and introduces no extra client-side code processing.&lt;/p&gt;
&lt;h2 id="1-why-doesnt-hugo-code-highlighting-follow-theme-changes"&gt;1. Why Doesn&amp;rsquo;t Hugo Code Highlighting Follow Theme Changes?
&lt;/h2&gt;&lt;p&gt;Hugo uses &lt;strong&gt;Chroma&lt;/strong&gt; as its built-in syntax highlighting engine. It generates highlighted HTML during the site build process.&lt;/p&gt;
&lt;p&gt;Chroma supports two main output modes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Inline Styles:&lt;/strong&gt; Color information is written directly into the HTML elements through their &lt;code&gt;style&lt;/code&gt; attributes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CSS Classes:&lt;/strong&gt; Syntax elements receive CSS classes, while external stylesheets control their appearance.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When inline styles are enabled, the generated HTML may look something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-html" data-lang="html"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;highlight&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;pre&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;color:#24292e;background-color:#fff&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ...
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;pre&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This creates a problem.&lt;/p&gt;
&lt;p&gt;The code block&amp;rsquo;s colors are already embedded in the generated HTML. When the frontend theme changes, updating CSS classes or HTML attributes cannot easily override those inline styles using ordinary CSS rules.&lt;/p&gt;
&lt;p&gt;The solution is straightforward:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Configure Chroma to use CSS classes instead of inline styles.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Once this is done, we can control syntax highlighting entirely through CSS.&lt;/p&gt;
&lt;h2 id="2-the-solution-use-two-static-css-themes"&gt;2. The Solution: Use Two Static CSS Themes
&lt;/h2&gt;&lt;p&gt;The implementation consists of four steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Disable Chroma&amp;rsquo;s inline styles.&lt;/li&gt;
&lt;li&gt;Generate separate light and dark syntax highlighting stylesheets.&lt;/li&gt;
&lt;li&gt;Use Hugo Theme Stack&amp;rsquo;s theme attribute to control the active styles.&lt;/li&gt;
&lt;li&gt;Scope the dark theme styles using SCSS.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following example uses &lt;code&gt;hugo-theme-stack&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="step-1-update-your-hugo-configuration"&gt;Step 1: Update Your Hugo Configuration
&lt;/h3&gt;&lt;p&gt;Open your project&amp;rsquo;s &lt;code&gt;hugo.toml&lt;/code&gt; (or &lt;code&gt;config.toml&lt;/code&gt;) and add the following configuration:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-toml" data-lang="toml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;markup&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;markup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;highlight&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;noClasses&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;codeFences&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;guessSyntax&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The most important setting is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-toml" data-lang="toml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;noClasses&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This tells Hugo to generate CSS classes for syntax highlighting instead of embedding colors directly into HTML elements.&lt;/p&gt;
&lt;p&gt;Keep in mind:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;false&lt;/code&gt; enables CSS class-based highlighting.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;true&lt;/code&gt; enables inline styles.&lt;/li&gt;
&lt;li&gt;This configuration belongs under &lt;code&gt;[markup.highlight]&lt;/code&gt;, not inside &lt;code&gt;[params]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="step-2-generate-two-chroma-stylesheets"&gt;Step 2: Generate Two Chroma Stylesheets
&lt;/h3&gt;&lt;p&gt;Hugo includes a built-in command for generating Chroma stylesheets.&lt;/p&gt;
&lt;p&gt;Run the following commands from your project root:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Generate the light theme&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;hugo gen chromastyles --style&lt;span class="o"&gt;=&lt;/span&gt;github &amp;gt; assets/scss/syntax-light.scss
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Generate the dark theme&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;hugo gen chromastyles --style&lt;span class="o"&gt;=&lt;/span&gt;github-dark &amp;gt; assets/scss/syntax-dark.scss
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The two styles used here are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;github&lt;/code&gt;: A syntax highlighting theme designed for light backgrounds.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;github-dark&lt;/code&gt;: A syntax highlighting theme designed for dark backgrounds.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; We use the &lt;code&gt;.scss&lt;/code&gt; extension instead of &lt;code&gt;.css&lt;/code&gt; so that Sass can process and inline these files when importing them. This is necessary for the nested SCSS import in the next step.&lt;/p&gt;
&lt;p&gt;If the &lt;code&gt;assets/scss/&lt;/code&gt; directory does not exist, create it first:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mkdir -p assets/scss
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can also choose other Chroma styles that better match your website&amp;rsquo;s design.&lt;/p&gt;
&lt;h3 id="step-3-update-customscss"&gt;Step 3: Update custom.scss
&lt;/h3&gt;&lt;p&gt;&lt;code&gt;hugo-theme-stack&lt;/code&gt; provides an extension point for custom styles through &lt;code&gt;assets/scss/custom.scss&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Open or create this file and add the following code:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-scss" data-lang="scss"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;/* ==========================================
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; Chroma Syntax Highlighting Theme Switching
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; ========================================== */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// 1. Use the light syntax highlighting theme by default
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;syntax-light&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// 2. Switch to the dark syntax highlighting theme
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// when Hugo Theme Stack enables Dark Mode
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;data-scheme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;dark&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;syntax-dark&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The important part is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-scss" data-lang="scss"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;data-scheme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;dark&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;syntax-dark&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Because &lt;code&gt;syntax-dark.scss&lt;/code&gt; is an SCSS file, Sass processes its contents and nests the generated CSS rules within the specified selector scope.&lt;/p&gt;
&lt;p&gt;The resulting CSS will behave similarly to this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-css" data-lang="css"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;chroma&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c"&gt;/* Light Mode styles */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;data-scheme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;dark&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;chroma&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c"&gt;/* Dark Mode styles */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This gives us two independent sets of syntax highlighting styles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Light Mode: Uses &lt;code&gt;syntax-light.scss&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Dark Mode: Uses &lt;code&gt;syntax-dark.scss&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When users switch themes, the browser simply applies the matching CSS rules based on the HTML attribute.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Background color adjustment&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If the code block background is still being overridden by the theme&amp;rsquo;s default styles, inspect the computed CSS rules using your browser&amp;rsquo;s developer tools.&lt;/p&gt;
&lt;p&gt;For example, if your dark Chroma theme uses &lt;code&gt;#24292e&lt;/code&gt; as its background color, you can add:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-scss" data-lang="scss"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;data-scheme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;dark&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nc"&gt;.highlight&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nc"&gt;.chroma&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#24292e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Adjust the selectors and background color according to your actual generated Chroma styles and theme structure.&lt;/p&gt;
&lt;p&gt;Avoid adding &lt;code&gt;!important&lt;/code&gt; everywhere unless there is a specific CSS conflict that requires it.&lt;/p&gt;
&lt;h3 id="step-4-rebuild-and-verify"&gt;Step 4: Rebuild and Verify
&lt;/h3&gt;&lt;p&gt;After updating the configuration and SCSS files, restart your Hugo development server:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;hugo server --disableFastRender
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To verify that everything is working, open your browser&amp;rsquo;s developer tools and inspect a code block.&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;noClasses = false&lt;/code&gt; correctly configured, the generated HTML should look similar to this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-html" data-lang="html"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;highlight&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;chroma&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;pre&lt;/span&gt; &lt;span class="na"&gt;tabindex&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;0&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;chroma&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ...
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;pre&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The exact HTML structure may vary depending on your Hugo version, Markdown rendering configuration, and theme templates.&lt;/p&gt;
&lt;p&gt;The important thing is that syntax highlighting colors should now be controlled by CSS classes rather than inline &lt;code&gt;style&lt;/code&gt; attributes.&lt;/p&gt;
&lt;p&gt;Now switch between the two theme modes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Light Mode: Code blocks should display the GitHub light color scheme.&lt;/li&gt;
&lt;li&gt;Dark Mode: Code blocks should display the GitHub Dark color scheme.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the changes do not appear immediately, try a hard refresh:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Windows/Linux: &lt;code&gt;Ctrl + Shift + R&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;macOS: &lt;code&gt;Cmd + Shift + R&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also check whether Hugo has successfully rebuilt your custom SCSS.&lt;/p&gt;
&lt;h2 id="3-common-questions"&gt;3. Common Questions
&lt;/h2&gt;&lt;h3 id="q1-why-doesnt-syntax-highlighting-change-after-setting-noclasses--false"&gt;Q1: Why Doesn&amp;rsquo;t Syntax Highlighting Change After Setting &lt;code&gt;noClasses = false&lt;/code&gt;?
&lt;/h3&gt;&lt;p&gt;First, make sure Hugo is loading the correct configuration file.&lt;/p&gt;
&lt;p&gt;Then inspect the generated HTML:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If syntax colors are still defined through inline &lt;code&gt;style&lt;/code&gt; attributes, the configuration may not have been applied.&lt;/li&gt;
&lt;li&gt;If elements have classes such as &lt;code&gt;.chroma&lt;/code&gt; or &lt;code&gt;.hl&lt;/code&gt;, Chroma is already using class-based highlighting. The next step is to check whether your CSS is being loaded correctly.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="q2-why-are-code-blocks-still-white-in-dark-mode"&gt;Q2: Why Are Code Blocks Still White in Dark Mode?
&lt;/h3&gt;&lt;p&gt;There are usually two possible reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The dark syntax stylesheet was not imported or generated correctly.&lt;/li&gt;
&lt;li&gt;The theme&amp;rsquo;s default code block background styles are overriding Chroma&amp;rsquo;s background settings.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Use your browser&amp;rsquo;s developer tools to inspect the computed styles of &lt;code&gt;.highlight&lt;/code&gt; and &lt;code&gt;.chroma&lt;/code&gt;. This will help identify which CSS rule is actually taking effect.&lt;/p&gt;
&lt;h3 id="q3-do-i-need-prismjs-or-highlightjs"&gt;Q3: Do I Need Prism.js or Highlight.js?
&lt;/h3&gt;&lt;p&gt;No.&lt;/p&gt;
&lt;p&gt;Hugo already handles syntax highlighting through Chroma during the build process.&lt;/p&gt;
&lt;p&gt;Once Chroma uses CSS classes, you can control the colors entirely through static stylesheets. There is no need to introduce another client-side syntax highlighting library.&lt;/p&gt;
&lt;h2 id="4-conclusion"&gt;4. Conclusion
&lt;/h2&gt;&lt;p&gt;The reason Hugo code highlighting often fails to follow Dark/Light theme changes is usually not the theme switcher itself, but how syntax highlighting styles are generated.&lt;/p&gt;
&lt;p&gt;The solution comes down to three key steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Set &lt;code&gt;noClasses = false&lt;/code&gt; to make Chroma use CSS classes.&lt;/li&gt;
&lt;li&gt;Generate separate light and dark stylesheets with &lt;code&gt;hugo gen chromastyles&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;html[data-scheme=&amp;quot;dark&amp;quot;]&lt;/code&gt; and SCSS to scope dark theme styles.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This approach offers several advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fully static:&lt;/strong&gt; No additional JavaScript highlighting libraries are required.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lightweight:&lt;/strong&gt; Syntax highlighting is handled during Hugo&amp;rsquo;s build process.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maintainable:&lt;/strong&gt; Light and dark color schemes are managed independently.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Theme-friendly:&lt;/strong&gt; It integrates directly with Hugo Theme Stack&amp;rsquo;s existing &lt;code&gt;data-scheme&lt;/code&gt; attribute.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For developers building technical blogs with Hugo and &lt;code&gt;hugo-theme-stack&lt;/code&gt;, this is a simple, lightweight, and maintainable way to keep code highlighting consistent across theme modes.&lt;/p&gt;</description></item></channel></rss>