Capítulo 12 de 29
Tailwind ships a large default color palette (over 20 color scales × 11 shades each, defined in OKLCH) that's available across every color-related utility (bg-*, text-*, border-*, fill-*, ring-*, etc.); colors are customized, extended, or replaced entirely the same way as any other theme value, via @theme.
50 (lightest) → 950 (darkest), e.g. bg-sky-50 … bg-sky-950.bg-* (background), text-* (text color), decoration-* (text-decoration color), border-*, outline-*, shadow-*/inset-shadow-* (shadow color), ring-*/inset-ring-* (ring color), accent-*, caret-*, scrollbar-thumb-*/scrollbar-track-*, fill-*/stroke-* (SVG) — the same color token works across all of them.bg-black/75 sets alpha to 75% via a trailing /<value>; supports arbitrary precision (bg-pink-500/[71.37%]) and a CSS-variable alpha (bg-cyan-400/(--my-alpha-value)).dark: variant, e.g. dark:bg-gray-800 (see Dark Mode chapter).--color-* CSS variable (var(--color-blue-500)); the --alpha() function adjusts a referenced color's opacity in hand-written CSS (--alpha(var(--color-gray-950) / 10%)), and colors work inside arbitrary values too (bg-[light-dark(var(--color-white),var(--color-gray-950))]).--color-* tokens in @theme (--color-midnight: #121063;) — this immediately makes bg-midnight, text-midnight, fill-midnight, etc. available.--color-<name>-<shade> variables in @theme — the new values replace the built-in ones project-wide.--color-lime-*: initial; removes just that scale (and its generated CSS variables/utilities) — useful for trimming unused output.--color-*: initial; wipes every default color, then define your own tokens from scratch under @theme.@theme inline (not plain @theme) when a color's value is itself var(...) pointing at another custom property (e.g. a [data-theme="dark"]-swapped brand variable) — this ensures Tailwind resolves it correctly instead of the reference becoming stale.--color-black/--color-white. Redefining a neutral scale to reuse another's values (e.g. making --color-gray-* equal to --color-slate-*) is a supported pattern.@theme {
--color-midnight: #121063; /* new custom color → bg-midnight, text-midnight, ... */
--color-lime-*: initial; /* drop one default scale */
}
:root { --acme-canvas-color: oklch(0.967 0.003 264.542); }
[data-theme="dark"] { --acme-canvas-color: oklch(0.21 0.034 264.665); }
@theme inline {
--color-canvas: var(--acme-canvas-color); /* must be `inline` because it references another variable */
}
@theme inline requirement when a color's value is itself a variable reference.--color-* token defined in @theme automatically becomes usable across every color utility (bg/text/border/fill/ring/...) — colors aren't registered per-utility.@theme inline specifically when a color value points at another CSS variable, not for ordinary literal color values.--color-<scale>-*: initial removes one scale; --color-*: initial removes all of them — both are the mechanism for trimming or fully replacing the default palette, not a config array.theme.css/colors.mdx reference — don't hand-copy the OKLCH table into project code; reference the generated --color-* variables or the utility classes instead.--color-*) among the full theme variable system documented there (fonts, spacing, breakpoints, etc.) — the same @theme/initial/inline mechanics apply everywhere.dark: variant usage with color utilities.--alpha() and arbitrary-value color syntax in depth.