diff --git a/FSharp.Formatting.sln b/FSharp.Formatting.sln
index 14dbe4c4..b57604b9 100644
--- a/FSharp.Formatting.sln
+++ b/FSharp.Formatting.sln
@@ -125,6 +125,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{FAD5
docs\content\fsdocs-search.js = docs\content\fsdocs-search.js
docs\content\fsdocs-tips.js = docs\content\fsdocs-tips.js
docs\content\fsdocs-theme-toggle.js = docs\content\fsdocs-theme-toggle.js
+ docs\content\fsdocs-theme-set-dark.js = docs\content\fsdocs-theme-set-dark.js
EndProjectSection
EndProject
Global
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 033820f4..ef1abf52 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -1,5 +1,10 @@
# Changelog
+## 20.0.0-beta-002 - 2024-02-08
+
+### Fixed
+* Avoid theme flicker in dark mode. [#901](https://github.com/fsprojects/FSharp.Formatting/pull/901)
+
## 20.0.0-beta-001 - 2024-01-31
### Changed
diff --git a/docs/_template.html b/docs/_template.html
index 2f191021..9b6ac0aa 100644
--- a/docs/_template.html
+++ b/docs/_template.html
@@ -21,6 +21,7 @@
+
{{fsdocs-head-extra}}
diff --git a/docs/content/fsdocs-theme-set-dark.js b/docs/content/fsdocs-theme-set-dark.js
new file mode 100644
index 00000000..b6eeaba3
--- /dev/null
+++ b/docs/content/fsdocs-theme-set-dark.js
@@ -0,0 +1,5 @@
+const prefersDark = window.matchMedia("@media (prefers-color-scheme: dark)").matches;
+let currentTheme = localStorage.getItem('theme') ?? (prefersDark ? 'dark' : 'light');
+if (currentTheme === 'dark') {
+ window.document.documentElement.setAttribute("data-theme", 'dark');
+}
diff --git a/docs/content/fsdocs-theme-toggle.js b/docs/content/fsdocs-theme-toggle.js
index 5254e3ad..5e32f9e3 100644
--- a/docs/content/fsdocs-theme-toggle.js
+++ b/docs/content/fsdocs-theme-toggle.js
@@ -2,9 +2,6 @@
const prefersDark = window.matchMedia("@media (prefers-color-scheme: dark)").matches;
let currentTheme = localStorage.getItem('theme') ?? (prefersDark ? 'dark' : 'light');
-if (currentTheme === 'dark') {
- window.document.documentElement.setAttribute("data-theme", 'dark');
-}
export class ThemeToggle extends LitElement {
static properties = {