The @source directive tells Tailwind CSS where to look for utility class names in your project files. This is the CSS equivalent of the content configuration option.
Syntax
Basic Usage
Single Source Path
Define a glob pattern to scan for class names:
Tailwind will scan all .html, .js, and .jsx files in the ./src directory and its subdirectories.
Multiple Source Paths
You can specify multiple @source directives:
Quoted Paths Required
Source paths must be wrapped in quotes (single or double).
Negating Paths
Exclude specific paths using the not keyword:
This scans all JavaScript files in ./src except those in ./src/vendor.
Multiple Negations
Inline Candidates
The inline() function allows you to specify utility classes directly in CSS, ensuring they’re always included:
Basic Inline
This guarantees that flex, items-center, and justify-center are always generated, even if they’re not found in your source files.
Use Cases for Inline
Brace Expansion
Inline sources support brace expansion for generating multiple candidates:
Expands to:
Numeric Ranges
Generate numeric sequences:
Expands to:
Complex Expansions
Combine multiple patterns:
Expands to:
Negating Inline Candidates
Exclude specific inline candidates:
This includes flex and block but excludes grid.
Path Resolution
Paths are resolved relative to the CSS file’s location or the configured base directory.
Relative Paths
Absolute-like Paths
Base Directory
When using the compile API, paths are resolved from the base option:
Restrictions
Top-level Only
@source must be at the top level and cannot be nested inside other rules.
No Body
@source cannot have a body with CSS rules.
Using with @tailwind utilities
The @tailwind utilities directive can also specify a source path:
Or use source(none) to disable automatic scanning:
This is useful when you want complete control via @source directives:
Parsing Logic
From the source code (index.ts:256-307), here’s how @source is processed:
Output
The @source directive is removed from the final CSS output. It only affects which utility classes are generated:
API Usage
When using the JavaScript API, sources are returned: