- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
Frakment ships dark mode through CSS variables. Every token has a light and dark value. Toggling the .dark class on <html> swaps the entire palette, no JavaScript required at the component level.
This page covers the CSS layer. Framework guides cover how to toggle the class on load without a flash.
How it works
Every token in theme.css has two values:
:root {
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
--muted: oklch(0.97 0 0);
--border: oklch(0.92 0 0);
}
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
--muted: oklch(0.269 0 0);
--border: oklch(1 0 0 / 10%);
}@custom-variant dark (&:is(.dark *)) registers the dark: Tailwind variant. It activates whenever a .dark ancestor exists, so components can scope overrides locally:
<div className="bg-background dark:bg-muted">Toggle the class
Add or remove dark on the <html> element. Any of these works:
next-themes- handles persistence, system preference, and FOUC- A manual script - reads
localStorageand sets the class before hydration - A cookie - server-readable, no flash on first paint
The framework guides below cover each path.
Framework guides
System preference
Respect the OS setting on first load with prefers-color-scheme:
@media (prefers-color-scheme: dark) {
:root:not(.light) {
/* dark tokens */
}
}next-themes and the framework guides handle this automatically. Only add the media query if you do not use a theme library.
Per-section theming
Force a section to stay light or dark regardless of the page theme:
<div className="light bg-background text-foreground">
{/* always light */}
</div>
<div className="dark bg-background text-foreground">
{/* always dark */}
</div>The dark class on any ancestor activates the dark: variant for its subtree. The light class removes .dark from that subtree.
Accessibility
- Do not toggle on scroll. Users set their preference once.
- Respect the OS preference on first visit. All guides start with
system. - Contrast is guaranteed at the token level.
foregroundandbackgroundmeet WCAG AA in both modes. - Animate the swap only on explicit toggle. Use
disableTransitionOnChangefromnext-themes.
Next
- Theming - token reference
- Next.js dark mode - App Router setup
- Components - browse the catalog