agentleFS
casooncasoon/ai-agent-config/skills/darkmode/SKILL.md

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.

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
  1. Very specific:

    Use the Cookie Store API only if your target browsers support it.

    line 83

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

PrincipleLightDark
BackgroundWarm off-whiteWarm dark (never pure black)
TextNear-blackOff-white (never pure white)
BordersLight grayMuted dark
AccentsAdjust brightnessLighten 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

MistakeFix
#000 backgroundUse warm dark, e.g. #1e2628, #222a2c
#fff text on darkUse off-white, e.g. #e6e1dc, #d2cdc8
Cold grays in dark modeUse warm-tinted grays (teal/sand undertone)
Same accent in both modesLighten or warm the accent on dark surfaces
@media (prefers-color-scheme) inside scoped stylesUse :global(html.dark) for class-based toggle
Forgetting dark:border-*Borders are very visible in dark mode — always pair

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.