CSS variables are standard CSS features. You can define them anywhere in CSS and then use var(--variable-name) inside Tailwind utility classes by using square bracket notation, e.g., bg-[var(--my-color)].
To use a CSS variable in Tailwind, you wrap the var(--variable) inside square brackets after the utility prefix, like bg-[var(--main-bg)].
/* CSS */ :root { --box-color: #4ade80; } /* HTML */ <div class="w-40 h-40 bg-[var(--box-color)]"></div>
The CSS variable --box-color is set to a green shade (#4ade80). The Tailwind class uses bg-[var(--box-color)] to apply that color as background, so the box will appear green.
Tailwind uses square brackets to accept arbitrary CSS values. To use a CSS variable for text color, write text-[var(--btn-text)].
Accessibility requires colors to have enough contrast. When using CSS variables, you must define colors that meet these standards and test them. Tailwind does not automatically fix contrast issues.