Usage
Examples of how to use our core utilities.
This guide uses Next.js for demonstration purposes. Before using our framework, ensure you have configured your Tailwind CSS setup correctly.
In particular, we will showcase the most common use case: semantic color theming.
1. Set up utilities in your global CSS file
First, initialize the utilities in your project's global CSS file. This will allow you to dynamically control your theme variables throughout your app.
2. Apply the dynamic theme in your layout.tsx
Next, integrate your dynamic theme into your app’s root layout.
We will fetch the theme, generate the necessary CSS variables, and inject them into the <head>
of the document.
Notes:
generateSemanticColorCSSVariables(theme)
takes the fetched theme and generates semantic CSS variables automatically. If you need more control over how CSS variables are generated, use the lower-levelgenerateCSSVariables
function instead.wrapInRoot
ensures the CSS variables are scoped to the :root.
3. Use semantic colors in your components
Now you can use your semantic color tokens directly in your components with Tailwind utility classes.
For example, using bg-primary
to apply the primary background color:
Notes:
bg-primary
refers to the--color-primary
CSS variable you defined dynamically.- You can extend this system to use multiple semantic tokens like
bg-secondary
,text-primary
, etc., depending on your theme configuration.
Summary
By using dynamic theming with SSR (Server-Side Rendering), you gain full control over your app’s theme at runtime without relying on client-side JavaScript. Because the theme is generated and injected on the server, there is no visible color shift or flash during page load, resulting in a smoother and more consistent user experience.