This article will show you how to:
- define new CSS Variables
- define new classes in TailWind and use them
Steps
To add new tokens in the global CSS file, you need to,
- define them under :root and .dark,
- expose them to Tailwind with @theme inline.
Naming convention and Contrast
In the Base/Radium UI / Tailwind's semantic token model, they use as suffix the term foreground.
This term means: the content that sits on top of a background.
For instance,
- --highlight is the background color of the element
- --highlight-foreground is the text/icon color rendered ON TOP of that background
The mental model is:
- highlight is a surface,
- and it's foreground is what you draw on that surface.
They are always defined as a pair to ensure a readable contrast between background and content.
Add them in the global CSS file
Open the global CSS file and define them under :root and .dark,
Expose them to TailWind
Use them
You can now use them:
My highlight