Tailwind Rainbow
A VS Code extension that provides syntax highlighting for Tailwind CSS classes with customizable coloring themes.
Features
- 🟣 Prefix-based coloring: Colors Tailwind prefixes (hover, focus, sm, lg, etc.) individually
- 🔵 Arbitrary values: Highlights arbitrary prefix values and standalone arbitrary classes
- 🟠 Optional base class support: Highlights base classes with wildcard patterns (
bg-*, text-*, etc.)
- 🟡 Smart detection: Works in HTML, JSX, template literals, CSS @apply directives, and more
- 🟢 Fully configurable: Customize patterns, functions, and detection logic
- 🔴 Important classes: Highlights the
! in both !flex and flex!
Class Structure Analysis
The extension recognizes two main types of Tailwind constructs:
Prefixes - Modifiers that end with a colon (:)
- Examples:
hover:, sm:, dark:, group-hover:
- Checked against the
prefix section of the theme
Base Classes - Standalone utility classes without colons
- Examples:
bg-blue-500, text-lg, min-w-[100px]
- Checked against the
base section of the theme
Coloring Logic Examples
These are only examples. The default themes do not contain any entries in the base section.
Single Classes
/* Base class - uses base section */
bg-blue-500 → matches "bg-*" pattern in base section
/* Arbitrary class - uses arbitrary color */
[aspect-ratio:1/8] → uses arbitrary color
/* Prefixed class - prefix color applies to entire class */
hover:bg-red-500 → "hover" color from prefix section
Multi-Prefix Classes
/* Each prefix gets its own color, last prefix colors the rest */
lg:checked:hover:bg-blue-500
├─ lg: → "lg" color from prefix section
├─ checked: → "checked" color from prefix section
└─ hover:bg-blue-500 → "hover" color from prefix section
Advanced Multi-Token Coloring
/* When both prefix and base class have theme entries */
lg:min-w-[1920px]
├─ lg: → "lg" color (from prefix section)
└─ min-w-[1920px] → "min-*" color (from base section)
Wildcard Pattern Matching
Use the first part of a class name followed by -*, such as bg-* or min-*:
Prefix Wildcards
min-* in prefix section matches: min-lg:, min-xl:, min-[480px]:
- Exact matches take priority:
min-lg config overrides min-* config
Base Class Wildcards
bg-* in base section matches: bg-red-500, bg-[#ff0000], bg-gradient-to-r
min-* in base section matches: min-w-full, min-h-[100px]
Arbitrary Value Handling
/* Standalone arbitrary classes */
[aspect-ratio:1/8] → arbitrary color
/* Arbitrary prefixes */
[&.show]:block → arbitrary color
Configuration Priority
The extension follows a specific lookup order for maximum flexibility:
For Prefixes:
- Arbitrary color (for bracket-enclosed prefixes)
- Exact match in prefix section
- Match without ignored modifiers (e.g.,
group-hover → hover)
- Match without group name (e.g.,
hover/button → hover)
- Wildcard pattern match in prefix section
For Base Classes:
- Arbitrary color (for bracket-enclosed classes)
- Exact match in base section
- Wildcard pattern match in base section
- Matching styled collection
Disabled matching rules suppress lower-priority rules. Prefix colors can still
extend over an unstyled utility in class mode.
Supported File Types
- HTML, JavaScript, TypeScript
- React (JSX/TSX), Vue, Svelte, Astro
- PHP templates
- CSS, SCSS, Sass, Less, Stylus, PostCSS
- Template literals and CSS-in-JS
Installation
Requires VS Code 1.96 or newer.
- Open Extensions in VS Code (
Ctrl+Shift+X / Cmd+Shift+X)
- Search for Tailwind Rainbow by esdete and click Install, or use the Marketplace page
- Open a file with Tailwind CSS classes; highlighting starts automatically
If you have a downloaded .vsix file, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P), run Extensions: Install from VSIX… and select the file. Reload VS Code if prompted.
Configuration
Coloring Mode
{
"tailwindRainbow.mode": "prefix"
}
class (default): the final prefix color extends over an otherwise unstyled utility.
prefix: each prefix color stops after its colon. Utilities keep their normal editor color unless a base or collection rule styles them.
Base/collection colors and the ! important-marker style work independently in both modes.
Collections
Collections let one theme rule style a related set of utilities. Their names follow
Tailwind's documentation categories:
| Collection |
Examples |
layout |
flex, grid, hidden, absolute, overflow-hidden |
flexboxGrid |
flex-col, grid-cols-3, gap-4, items-center |
spacing |
p-4, px-2, m-auto, -mt-2, space-x-4 |
sizing |
w-full, min-w-0, h-8, size-4 |
typography |
text-lg, text-red-500, font-bold, leading-6 |
backgrounds |
bg-red-500, bg-cover, from-blue-500 |
borders |
border, border-red-500, rounded-lg, ring-2 |
effects |
shadow-md, text-shadow-sm, opacity-50, mask-linear-45 |
filters |
blur-sm, brightness-125, backdrop-blur-sm |
tables |
table-auto, border-collapse, border-spacing-2 |
transitionsAnimation |
transition-colors, duration-300, animate-spin |
transforms |
rotate-45, -translate-x-2, scale-95 |
interactivity |
cursor-pointer, pointer-events-none, select-none |
svg |
fill-red-500, stroke-2 |
accessibility |
forced-color-adjust-none |
Assign colors inside a theme. Built-in themes leave collection styles empty:
{
"tailwindRainbow.themes": {
"default": {
"collections": {
"spacing": { "color": "#B084EB" },
"flexboxGrid": { "color": "#61AFEF" }
}
}
}
}
Define a custom collection or replace a predefined one with an array:
{
"tailwindRainbow.collections": {
"buttons": ["btn", "btn-*"],
"spacing": ["p-*", "px-*", "m-*"],
"filters": []
},
"tailwindRainbow.themes": {
"default": {
"collections": {
"buttons": { "color": "#61AFEF" },
"spacing": { "color": "#B084EB" }
}
}
}
}
Arrays replace the full definition. In this example, spacing no longer includes
py-* or negative margins, and filters is empty. Omitted names retain their
predefined contents. Definitions apply across themes; colors belong to each theme.
Entries are exact class names or literal prefixes ending in -*. For example,
btn-*, grid-cols-* and -mx-* work; p*-*, * and regular expressions do not.
An exact entry is needed for btn itself. Values inside brackets or parentheses
remain part of the utility, and ! is handled separately.
Existing base rules win over collection styles. Among overlapping collections,
configured definitions are checked in their written order, followed by untouched
predefined collections. Only collections with a theme style participate; an
enabled: false style stops lower-priority collection rules. Unmodified predefined
categories use exact names and the most specific family to keep text-shadow-*
in Effects and border-collapse in Tables, even if only a broader category is styled.
Collections follow the v4 documentation categories, so bare flex and grid are
display utilities in Layout. sr-only and not-sr-only are also in Layout; v3
documents them under Accessibility. Recognized v3 spellings remain available.
Collection matching identifies utility families, not every valid Tailwind value:
custom utilities, namespaces and unknown families can be assigned explicitly.
Bare arbitrary properties such as [padding:1rem] retain their arbitrary style.
See collection definitions and coverage for the full lists
and source links.
Switching Themes
- Open Command Palette (
Ctrl+Shift+P / Cmd+Shift+P)
- Type "Tailwind Rainbow: Select Theme"
- Choose from available themes:
default, synthwave
Supported Languages
Configure which file types to process:
{
"tailwindRainbow.languages": [
"html",
"javascript",
"typescript",
"javascriptreact",
"typescriptreact",
"vue",
"svelte",
"astro",
"php",
"css",
"scss",
"sass",
"less",
"stylus",
"postcss",
"tailwindcss"
]
}
Custom Themes
Create or override themes with the following structure:
{
"tailwindRainbow.themes": {
"myTheme": {
"prefix": {
"hover": { "color": "#ff0000", "fontWeight": "bold" },
"focus": { "color": "#00ff00", "fontWeight": "normal" },
"sm": { "color": "#0000ff" },
"lg": { "color": "#ffff00" }
},
"base": {
"bg-*": { "color": "#ff6600", "fontWeight": "semibold" },
"text-*": { "color": "#6600ff" },
"p-*": { "color": "#00ffff" }
},
"arbitrary": { "color": "#ff00ff", "fontWeight": "bold" },
"important": { "color": "#ff0000", "fontWeight": "bold" }
}
},
"tailwindRainbow.theme": "myTheme"
}
Advanced Configuration
Class Detection Patterns
Customize how classes are detected in different contexts:
These lists replace the defaults, so include any existing names you want to keep. Highlighting applies to class attributes, configured helper functions and tagged templates; ordinary strings are left unchanged.
{
"tailwindRainbow.classIdentifiers": [
"class",
"className",
"class:",
"className:",
"classlist",
"classes",
"css",
"style"
],
"tailwindRainbow.classFunctions": ["cn", "clsx", "cva", "classNames", "classList", "twMerge", "tw", "styled", "css"],
"tailwindRainbow.templatePatterns": ["class", "tw`", "css`", "styled"],
"tailwindRainbow.contextPatterns": ["variants", "cva", "class", "css", "style", "@apply"]
}
Ignored Prefix Modifiers
Configure which prefix modifiers to ignore during parsing. For example, when using Tailwind's group-hover pattern the extension will ignore the group modifier and color the entire prefix with the hover color:
{
"tailwindRainbow.ignoredPrefixModifiers": ["group", "peer", "has", "in", "not"]
}
Extension API
Other extensions can register custom themes:
// Wait for activation
const tailwindRainbow = vscode.extensions.getExtension('esdete.tailwind-rainbow');
if (tailwindRainbow && !tailwindRainbow.isActive) {
await tailwindRainbow.activate();
}
// Register theme
const api = tailwindRainbow?.exports;
if (api) {
api.registerTheme('myCustomTheme', {
prefix: {
hover: { color: '#ff0000', fontWeight: 'bold' },
// ... more prefixes
},
base: {
'bg-*': { color: '#00ff00' },
// ... more base patterns
},
arbitrary: { color: '#0000ff' },
important: { color: '#ff00ff' },
});
}
Contributing
You have an idea for a new feature or found a bug? Feel free to open an issue or submit a pull request!
- Report bugs or request features via GitHub Issues
- Submit pull requests with improvements
- Share your custom themes with the community
License
Apache 2.0 License - see the LICENSE file for details