a dark theme for shadcn/ui

a dark theme is a shadcn/ui theme built around a purple primary color (#8e2589) with pink accents (#8e2554). The light mode uses a neutral background (#fdfcfd). Dark mode keeps the purple primary (#8e2589) on a neutral background (#000000).

Color palette

TokenLightDark
Background
#fdfcfdwhite
#000000black
Foreground
#10050fblack
#fdfcfdwhite
Card
#fcf8fcsnow
#030303black
Card foreground
#0c040bblack
#ffffffwhite
Popover
#fcf8fcsnow
#030303black
Popover foreground
#0c040bblack
#ffffffwhite
Primary
#8e2589darkmagenta
#8e2589darkmagenta
Primary foreground
#faebf9lavenderblush
#faebf9lavenderblush
Secondary
#5f258erebeccapurple
#5f258erebeccapurple
Secondary foreground
#f3ebfawhitesmoke
#f3ebfawhitesmoke
Muted
#dacee3gainsboro
#271c31darkslategray
Muted foreground
#454148darkslategray
#bab7besilver
Accent
#8e2554brown
#8e2554brown
Accent foreground
#faebf1lavenderblush
#faebf1lavenderblush
Destructive
#df0e07red
#f93b34tomato
Destructive foreground
#ffffffwhite
#ffffffwhite
Border
#e7e4e6gainsboro
#252225darkslategray
Input
#e7e4e6gainsboro
#252225darkslategray
Ring
#8e2589darkmagenta
#8e2589darkmagenta

Contrast

WCAG 2 contrast ratios between each background and its foreground color.

Light mode
Text on background19.49:1AAA
Text on card19.23:1AAA
Primary button6.61:1AA
Secondary button8.48:1AAA
Muted text6.63:1AA
Accent7.18:1AAA
Destructive5.00:1AA
Dark mode
Text on background20.51:1AAA
Text on card20.67:1AAA
Primary button6.61:1AA
Secondary button8.48:1AAA
Muted text8.18:1AAA
Accent7.18:1AAA
Destructive3.69:1AA Large

CSS variables

Paste this into your globals.css to use a dark theme in your shadcn/ui project.

:root {
  --radius: 0.5rem;
  --background: oklch(0.992 0.003 327.065);
  --foreground: oklch(0.139 0.032 328.761);
  --muted: oklch(0.868 0.031 310.11);
  --muted-foreground: oklch(0.383 0.013 310.134);
  --popover: oklch(0.983 0.006 327.093);
  --popover-foreground: oklch(0.125 0.027 328.521);
  --card: oklch(0.983 0.006 327.093);
  --card-foreground: oklch(0.125 0.027 328.521);
  --border: oklch(0.922 0.003 327.072);
  --input: oklch(0.922 0.003 327.072);
  --primary: oklch(0.469 0.18 330.174);
  --primary-foreground: oklch(0.955 0.025 327.275);
  --secondary: oklch(0.404 0.165 305.128);
  --secondary-foreground: oklch(0.95 0.022 310.224);
  --accent: oklch(0.444 0.146 357.542);
  --accent-foreground: oklch(0.953 0.018 348.337);
  --destructive: oklch(0.57 0.229 29.323);
  --destructive-foreground: oklch(1 0 180);
  --ring: oklch(0.469 0.18 330.174);
  --chart-1: oklch(0.469 0.18 330.174);
  --chart-2: oklch(0.404 0.165 305.128);
  --chart-3: oklch(0.444 0.146 357.542);
  --chart-4: oklch(0.428 0.176 305.043);
  --chart-5: oklch(0.473 0.186 330.267);
}

.dark {
  --radius: 0.5rem;
  --background: oklch(0 0 0);
  --foreground: oklch(0.992 0.001 327.048);
  --muted: oklch(0.25 0.041 308.865);
  --muted-foreground: oklch(0.784 0.01 310.313);
  --popover: oklch(0.092 0 180);
  --popover-foreground: oklch(1 0 180);
  --card: oklch(0.092 0 180);
  --card-foreground: oklch(1 0 180);
  --border: oklch(0.257 0.007 327.27);
  --input: oklch(0.257 0.007 327.27);
  --primary: oklch(0.469 0.18 330.174);
  --primary-foreground: oklch(0.955 0.025 327.275);
  --secondary: oklch(0.404 0.165 305.128);
  --secondary-foreground: oklch(0.95 0.022 310.224);
  --accent: oklch(0.444 0.146 357.542);
  --accent-foreground: oklch(0.953 0.018 348.337);
  --destructive: oklch(0.644 0.226 27.753);
  --destructive-foreground: oklch(1 0 180);
  --ring: oklch(0.469 0.18 330.174);
  --chart-1: oklch(0.469 0.18 330.174);
  --chart-2: oklch(0.404 0.165 305.128);
  --chart-3: oklch(0.444 0.146 357.542);
  --chart-4: oklch(0.428 0.176 305.043);
  --chart-5: oklch(0.473 0.186 330.267);
}