-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
51 lines (43 loc) · 1.48 KB
/
index.html
File metadata and controls
51 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- CRITICAL: Add this script BEFORE any stylesheets to prevent flash -->
<script>
(function() {
// Get saved theme from localStorage
const savedTheme = localStorage.getItem('theme');
// Determine if dark mode should be enabled
const isDark = savedTheme === 'dark' ||
(!savedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches);
// Apply theme immediately (before page renders)
if (isDark) {
document.documentElement.setAttribute('data-theme', 'dark');
}
})();
</script>
<!-- Your CSS files go here -->
<link rel="stylesheet" href="/src/styles/theme.css" />
<link rel="stylesheet" href="/src/index.css" />
<title>Fake Stack Overflow</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
<!--
HOW THIS WORKS:
1. Script runs IMMEDIATELY (before page renders)
2. Checks localStorage for saved theme preference
3. Falls back to system preference if no saved theme
4. Sets data-theme attribute on <html> element
5. CSS uses [data-theme="dark"] selector to apply dark styles
6. Page renders with correct theme (no flash!)
IMPORTANT: This script must be:
- In the <head>
- Before any <link> stylesheets
- Not async or defer
- Pure JavaScript (no React)
-->