diff --git a/src/format/html/format-html.ts b/src/format/html/format-html.ts
index 9f35fd599a..e2bfc2a983 100644
--- a/src/format/html/format-html.ts
+++ b/src/format/html/format-html.ts
@@ -609,7 +609,7 @@ export async function htmlFormatExtras(
giscusAfterBody,
renderEjs(
formatResourcePath("html", join("giscus", "giscus.ejs")),
- { giscus },
+ { giscus, darkMode: options.darkMode },
),
);
includeAfterBody.push(giscusAfterBody);
diff --git a/src/resources/formats/html/giscus/giscus.ejs b/src/resources/formats/html/giscus/giscus.ejs
index f12d537839..31f8377f8f 100644
--- a/src/resources/formats/html/giscus/giscus.ejs
+++ b/src/resources/formats/html/giscus/giscus.ejs
@@ -6,9 +6,11 @@
const getTheme = () => {
let baseTheme = document.getElementById('giscus-base-theme').value;
let altTheme = document.getElementById('giscus-alt-theme').value;
+ <% if (darkMode !== undefined) { %>
if (authorPrefersDark) {
[baseTheme, altTheme] = [altTheme, baseTheme];
}
+ <% } %>
return document.body.classList.contains('quarto-dark') ? altTheme : baseTheme;
};
const script = document.createElement("script");