Theming
Using CSS Variables or Tailwind CSS for theming.
You can choose between using CSS variables or Tailwind CSS utility classes for theming.
Utility classes
To use utility classes for theming set tailwind.cssVariables
to false
in your components.json
file.
CSS Variables
To use CSS variables for theming set tailwind.cssVariables to true in your components.json
file.
Convention
We use a simple background
and foreground
convention for colors. The background variable is used for the background color of the component and the foreground
variable is used for the text color.
The background
suffix is omitted when the variable is used for the
background color of the component.
Given the following CSS variables:
The background
color of the following component will be hsl(var(--primary))
and the foreground
color will be hsl(var(--primary-foreground))
.
CSS variables must be defined without color space function. See the Tailwind CSS documentation
Adding new colors
To add new colors, you need to add them to your CSS file and to your tailwind.config.ts
file.
You can now use the warning
utility class in your components.
Other color formats
For effective theming, I recommend leveraging HSL colors (Hue, Saturation, Lightness). HSL offers intuitive control over color properties, making it ideal for creating cohesive color schemes. However, if you prefer, other color formats can also be utilized. To explore a wide range of theme options specifically tailored for shadcn/ui, the resource at ui.jln.dev provides over 10,000 variations, offering ample inspiration and customization possibilities
See the Tailwind CSS documentation for more information on using rgb
, rgba
or hsl
colors.
Last updated on