darkmode
Skill1 starsChanged 46 days agoMITView on GitHub
Dark mode implementation for Astro + Tailwind v4 — class-based toggle, FOUC-free init script, cookie/localStorage persistence, and contrast-safe light/dark token pairing.
In this repository81 other files it gives its agents.
- accessibility-action-planSkill
- accessibility-auditSkill
- accessibility-finding-explainerSkill
- accessibility-report-summarySkill
- agent-config-authoringSkill
- agents-sdkSkill
- ai-ux-patternsSkill
- alt-text-generatorSkill
- anti-ai-copySkill
- aria-usage-reviewSkill
- astro-architectureSkill
- astro-client-scriptsSkill
- astro-component-a11y-reviewSkill
- before-after-accessibility-commsSkill
- bfsg-risk-language-softenerSkill
- biomeSkill
- blog-from-transcriptSkill
- brand-voice-dnaSkill
- case-study-from-auditSkill
- client-email-after-auditSkill
- cloudflare-email-serviceSkill
- cloudflare-one-migrationsSkill
- cloudflare-oneSkill
- cloudflareSkill
- complexity-judgmentSkill
- component-doc-writerSkill
- content-clarity-a11y-checkSkill
- content-qaSkill
- conversation-retrospectiveSkill
- deep-researchSkill
- design-directionsSkill
- design-systemsSkill
- durable-objectsSkill
- faq-from-issuesSkill
- form-accessibility-reviewSkill
- frontend-designSkill
- handoffSkill
- i18nSkill
- image-to-webpSkill
- keyboard-navigation-reviewSkill
- knowledge-baseSkill
- landing-and-site-builderSkill
- landingpage-from-briefingSkill
- lighthouse-axe-result-explainerSkill
- linkedin-post-from-contentSkill
- llm-councilSkill
- local-business-seoSkill
- mcp-builderSkill
- mdx-contentSkill
- motion-designSkill
- native-html-uiSkill
- newsletter-from-auditSkill
- overlay-tool-risk-explainerSkill
- playwrightSkill
- post-auditSkill
- remotionSkill
- sandbox-migrate-to-nextSkill
- sandbox-nextSkill
- sandbox-sdkSkill
- sandbox-stableSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 83
Use the Cookie Store API only if your target browsers support it.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Dark mode
Activation
Class-based (recommended — supports a toggle)
Tailwind v4 custom variant in the CSS entry:
@custom-variant dark (&:where(.dark, .dark *));FOUC-free init script in <head> — must be is:inline to run before paint:
<script is:inline>
function getStoredTheme() {
try {
return document.cookie.match(/(?:^|;\s*)theme=(dark|light)(?:;|$)/)?.[1]
|| localStorage.getItem('theme');
} catch (e) {
return null;
}
}
function applyTheme() {
var t = getStoredTheme();
document.documentElement.classList.remove('no-js');
if (t === 'dark' || (!t && matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}
applyTheme();
if (window.__applyThemeHandler) {
document.removeEventListener('astro:after-swap', window.__applyThemeHandler);
}
window.__applyThemeHandler = applyTheme;
document.addEventListener('astro:after-swap', window.__applyThemeHandler);
</script>Re-registering on astro:after-swap matters for ClientRouter (SPA transitions) so the theme persists across navigations.
OS-only (no toggle)
Tailwind v4 uses prefers-color-scheme by default — no configuration needed, just use dark: utilities.
Persistence
Cookie
document.cookie = 'theme=' + value + ';path=/;max-age=31536000;SameSite=Lax';Technical cookie — no consent banner required (UI preference, not tracking). Add domain= only when cross-subdomain persistence is a real requirement.
localStorage fallback
localStorage.setItem('theme', value);Toggle
btn.addEventListener('click', function () {
var isDark = document.documentElement.classList.toggle('dark');
var v = isDark ? 'dark' : 'light';
document.cookie = 'theme=' + v + ';path=/;max-age=31536000;SameSite=Lax';
try { localStorage.setItem('theme', v); } catch (e) {}
});Use the Cookie Store API only if your target browsers support it. Plain document.cookie remains the compatibility path.
CSS patterns
Scoped styles (Astro / Svelte)
<style>
.card { background: #f8f9fa; color: #1f2937; }
:global(html.dark) .card { background: #2a3234; color: #d2cdc8; }
</style>Tailwind utilities
<div class="bg-white dark:bg-slate-800 text-gray-900 dark:text-gray-100">Color guidelines
| Principle | Light | Dark |
| Background | Warm off-white | Warm dark (never pure black) |
| Text | Near-black | Off-white (never pure white) |
| Borders | Light gray | Muted dark |
| Accents | Adjust brightness | Lighten or warm up |
Contrast minimums (WCAG AA)
- Body text: 4.5:1.
- Large text (≥ 18 px bold / 24 px): 3:1.
- Interactive elements: 3:1.
Both modes must independently meet these — see the accessibility-audit skill for full pairing tables.
Logo handling
<img src="/logo.svg" class="block dark:hidden" alt="Logo" />
<img src="/logo-dark.svg" class="hidden dark:block" alt="Logo" />Common mistakes
| Mistake | Fix |
#000 background | Use warm dark, e.g. #1e2628, #222a2c |
#fff text on dark | Use off-white, e.g. #e6e1dc, #d2cdc8 |
| Cold grays in dark mode | Use warm-tinted grays (teal/sand undertone) |
| Same accent in both modes | Lighten or warm the accent on dark surfaces |
@media (prefers-color-scheme) inside scoped styles | Use :global(html.dark) for class-based toggle |
Forgetting dark:border-* | Borders are very visible in dark mode — always pair |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

