🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 59 (from laksa133)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
✅
CRAWLED
1 hour ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://tailwindcss.com/docs/detecting-classes-in-source-files
Last Crawled2026-04-13 17:10:44 (1 hour ago)
First Indexed2025-01-23 10:51:50 (1 year ago)
HTTP Status Code200
Meta TitleDetecting classes in source files - Core concepts - Tailwind CSS
Meta DescriptionUnderstanding and customizing how Tailwind scans your source files.
Meta Canonicalnull
Boilerpipe Text
Understanding and customizing how Tailwind scans your source files. Overview Tailwind works by scanning your project for utility classes, then generating all of the necessary CSS based on the classes you've actually used. This makes sure your CSS is as small as possible, and is also what makes features like arbitrary values possible. How classes are detected Tailwind treats all of your source files as plain text, and doesn't attempt to actually parse your files as code in any way. Instead it just looks for any tokens in your file that could be classes based on which characters Tailwind is expecting in class names: JSX export function Button ({ color , children }) { const color s = { black : " bg- black text- white " , blue : " bg- blue -500 text- white " , white : " bg- white text- black " , }; return ( < button className ={ ` ${ color s [ color ] } rounded-full px-2 py-1.5 font-sans text-sm/6 font-medium shadow ` }> { children } </ button > ) ; } Then it tries to generate the CSS for all of these tokens, throwing away any tokens that don't map to a utility class the framework knows about. Dynamic class names Since Tailwind scans your source files as plain text, it has no way of understanding string concatenation or interpolation in the programming language you're using. Don't construct class names dynamically HTML < div class = "text-{{ error ? 'red' : 'green' }}-600" ></ div > In the example above, the strings text-red-600 and text-green-600 do not exist, so Tailwind will not generate those classes. Instead, make sure any class names you’re using exist in full: Always use complete class names HTML < div class = "{{ error ? ' text-red-600 ' : ' text-green-600 ' }}" ></ div > If you're using a component library like React or Vue, this means you shouldn't use props to dynamically construct classes: Don't use props to build class names dynamically JSX function Button ({ color , children }) { return < button className ={ `bg- ${ color } -600 hover:bg- ${ color } -500 ...` }>{ children }</ button >; } Instead, map props to complete class names that are statically detectable at build-time: Always map props to static class names JSX function Button ({ color , children }) { const colorVariants = { blue : "bg-blue-600 hover:bg-blue-500" , red : "bg-red-600 hover:bg-red-500" , }; return < button className ={ ` ${ colorVariants [ color ] } ...` }>{ children }</ button >; } This has the added benefit of letting you map different prop values to different color shades for example: JSX function Button ({ color , children }) { const colorVariants = { blue : "bg-blue-600 hover:bg-blue-500 text-white" , red : "bg-red-500 hover:bg-red-400 text-white" , yellow : "bg-yellow-300 hover:bg-yellow-400 text-black" , }; return < button className ={ ` ${ colorVariants [ color ] } ...` }>{ children }</ button >; } As long as you always use complete class names in your code, Tailwind will generate all of your CSS perfectly every time. Which files are scanned Tailwind will scan every file in your project for class names, except in the following cases: Files that are in your .gitignore file Files in the node_modules directory Binary files like images, videos, or zip files CSS files Common package manager lock files If you need to scan any files that Tailwind is ignoring by default, you can explicitly register those sources. Explicitly registering sources Use @source to explicitly register source paths relative to the stylesheet: CSS @import "tailwindcss" ; @source "../node_modules/@acmecorp/ui-lib" ; This is especially useful when you need to scan an external library that is built with Tailwind, since dependencies are usually listed in your .gitignore file and ignored by Tailwind by default. Setting your base path Tailwind uses the current working directory as its starting point when scanning for class names by default. To set the base path for source detection explicitly, use the source() function when importing Tailwind in your CSS: CSS @import "tailwindcss" source ( "../src" ) ; This can be useful when working with monorepos where your build commands run from the root of the monorepo instead of the root of each project. Ignoring specific paths Use @source not to ignore specific paths, relative to the stylesheet, when scanning for class names: CSS @import "tailwindcss" ; @source not "../src/components/legacy" ; This is useful when you have large directories in your project that you know don't use Tailwind classes, like legacy components or third-party libraries. Disabling automatic detection Use source(none) to completely disable automatic source detection if you want to register all of your sources explicitly: CSS @import "tailwindcss" source ( none ); @source "../admin" ; @source "../shared" ; This can be useful in projects that have multiple Tailwind stylesheets where you want to make sure each one only includes the classes each stylesheet needs. Safelisting specific utilities If you need to make sure Tailwind generates certain class names that don’t exist in your content files, use @source inline() to force them to be generated: CSS @import "tailwindcss" ; @source inline( "underline" ) ; Generated CSS .underline { text-decoration-line : underline ; } Safelisting variants You can also use @source inline() to generate classes with variants. For example, to generate the underline class with hover and focus variants, add {hover:,focus:,} to the source input: CSS @import "tailwindcss" ; @source inline( "{hover:,focus:,}underline" ) ; Generated CSS .underline { text-decoration-line : underline ; } @media ( hover : hover ) { .hover \: underline:hover { text-decoration-line : underline ; } } @media ( focus : focus ) { .focus \: underline:focus { text-decoration-line : underline ; } } Safelisting with ranges The source input is brace expanded , so you can generate multiple classes at once. For example, to generate all the red background colors with hover variants, use a range: CSS @import "tailwindcss" ; @source inline( "{hover:,}bg-red-{50,{100..900..100},950}" ) ; Generated CSS .bg-red-50 { background-color : var ( --color-red-50 ); } .bg-red-100 { background-color : var ( --color-red-100 ); } .bg-red-200 { background-color : var ( --color-red-200 ); } /* ... */ .bg-red-800 { background-color : var ( --color-red-800 ); } .bg-red-900 { background-color : var ( --color-red-900 ); } .bg-red-950 { background-color : var ( --color-red-950 ); } @media ( hover : hover ) { .hover \: bg-red-50:hover { background-color : var ( --color-red-50 ); } /* ... */ .hover \: bg-red-950:hover { background-color : var ( --color-red-950 ); } } This generates red background colors from 100 to 900 in increments of 100, along with the first and last shades of 50 and 950. It also adds the hover: variant for each of those classes. Explicitly excluding classes Use @source not inline() to prevent specific classes from being generated, even if they are detected in your source files: CSS @import "tailwindcss" ; @source not inline( "{hover:,focus:,}bg-red-{50,{100..900..100},950}" ) ; This will explicitly exclude the red background utilities, along with their hover and focus variants, from being generated.
Markdown
v4.2 `⌘K``Ctrl K` [Docs](https://tailwindcss.com/docs)[Blog](https://tailwindcss.com/blog)[Showcase](https://tailwindcss.com/showcase)[Sponsor](https://tailwindcss.com/sponsor) [Plus](https://tailwindcss.com/plus?ref=top) 1. Core concepts 2. Detecting classes in source files - [Documentation](https://tailwindcss.com/docs/installation) - [Components](https://tailwindcss.com/plus/ui-blocks?ref=sidebar) - [Templates](https://tailwindcss.com/plus/templates?ref=sidebar) - [UI Kit](https://tailwindcss.com/plus/ui-kit?ref=sidebar) - [Playground](https://play.tailwindcss.com/) - [CourseNew](https://tailwindcss.com/build-uis-that-dont-suck) - [Community](https://tailwindcss.com/insiders) ### Getting started - [Installation](https://tailwindcss.com/docs/installation) - [Editor setup](https://tailwindcss.com/docs/editor-setup) - [Compatibility](https://tailwindcss.com/docs/compatibility) - [Upgrade guide](https://tailwindcss.com/docs/upgrade-guide) ### Core concepts - [Styling with utility classes](https://tailwindcss.com/docs/styling-with-utility-classes) - [Hover, focus, and other states](https://tailwindcss.com/docs/hover-focus-and-other-states) - [Responsive design](https://tailwindcss.com/docs/responsive-design) - [Dark mode](https://tailwindcss.com/docs/dark-mode) - [Theme variables](https://tailwindcss.com/docs/theme) - [Colors](https://tailwindcss.com/docs/colors) - [Adding custom styles](https://tailwindcss.com/docs/adding-custom-styles) - [Detecting classes in source files](https://tailwindcss.com/docs/detecting-classes-in-source-files) - [Functions and directives](https://tailwindcss.com/docs/functions-and-directives) ### Base styles - [Preflight](https://tailwindcss.com/docs/preflight) ### Layout - [aspect-ratio](https://tailwindcss.com/docs/aspect-ratio) - [columns](https://tailwindcss.com/docs/columns) - [break-after](https://tailwindcss.com/docs/break-after) - [break-before](https://tailwindcss.com/docs/break-before) - [break-inside](https://tailwindcss.com/docs/break-inside) - [box-decoration-break](https://tailwindcss.com/docs/box-decoration-break) - [box-sizing](https://tailwindcss.com/docs/box-sizing) - [display](https://tailwindcss.com/docs/display) - [float](https://tailwindcss.com/docs/float) - [clear](https://tailwindcss.com/docs/clear) - [isolation](https://tailwindcss.com/docs/isolation) - [object-fit](https://tailwindcss.com/docs/object-fit) - [object-position](https://tailwindcss.com/docs/object-position) - [overflow](https://tailwindcss.com/docs/overflow) - [overscroll-behavior](https://tailwindcss.com/docs/overscroll-behavior) - [position](https://tailwindcss.com/docs/position) - [top / right / bottom / left](https://tailwindcss.com/docs/top-right-bottom-left) - [visibility](https://tailwindcss.com/docs/visibility) - [z-index](https://tailwindcss.com/docs/z-index) ### Flexbox & Grid - [flex-basis](https://tailwindcss.com/docs/flex-basis) - [flex-direction](https://tailwindcss.com/docs/flex-direction) - [flex-wrap](https://tailwindcss.com/docs/flex-wrap) - [flex](https://tailwindcss.com/docs/flex) - [flex-grow](https://tailwindcss.com/docs/flex-grow) - [flex-shrink](https://tailwindcss.com/docs/flex-shrink) - [order](https://tailwindcss.com/docs/order) - [grid-template-columns](https://tailwindcss.com/docs/grid-template-columns) - [grid-column](https://tailwindcss.com/docs/grid-column) - [grid-template-rows](https://tailwindcss.com/docs/grid-template-rows) - [grid-row](https://tailwindcss.com/docs/grid-row) - [grid-auto-flow](https://tailwindcss.com/docs/grid-auto-flow) - [grid-auto-columns](https://tailwindcss.com/docs/grid-auto-columns) - [grid-auto-rows](https://tailwindcss.com/docs/grid-auto-rows) - [gap](https://tailwindcss.com/docs/gap) - [justify-content](https://tailwindcss.com/docs/justify-content) - [justify-items](https://tailwindcss.com/docs/justify-items) - [justify-self](https://tailwindcss.com/docs/justify-self) - [align-content](https://tailwindcss.com/docs/align-content) - [align-items](https://tailwindcss.com/docs/align-items) - [align-self](https://tailwindcss.com/docs/align-self) - [place-content](https://tailwindcss.com/docs/place-content) - [place-items](https://tailwindcss.com/docs/place-items) - [place-self](https://tailwindcss.com/docs/place-self) ### Spacing - [padding](https://tailwindcss.com/docs/padding) - [margin](https://tailwindcss.com/docs/margin) ### Sizing - [width](https://tailwindcss.com/docs/width) - [min-width](https://tailwindcss.com/docs/min-width) - [max-width](https://tailwindcss.com/docs/max-width) - [height](https://tailwindcss.com/docs/height) - [min-height](https://tailwindcss.com/docs/min-height) - [max-height](https://tailwindcss.com/docs/max-height) - [inline-size](https://tailwindcss.com/docs/inline-size) - [min-inline-size](https://tailwindcss.com/docs/min-inline-size) - [max-inline-size](https://tailwindcss.com/docs/max-inline-size) - [block-size](https://tailwindcss.com/docs/block-size) - [min-block-size](https://tailwindcss.com/docs/min-block-size) - [max-block-size](https://tailwindcss.com/docs/max-block-size) ### Typography - [font-family](https://tailwindcss.com/docs/font-family) - [font-size](https://tailwindcss.com/docs/font-size) - [font-smoothing](https://tailwindcss.com/docs/font-smoothing) - [font-style](https://tailwindcss.com/docs/font-style) - [font-weight](https://tailwindcss.com/docs/font-weight) - [font-stretch](https://tailwindcss.com/docs/font-stretch) - [font-variant-numeric](https://tailwindcss.com/docs/font-variant-numeric) - [font-feature-settings](https://tailwindcss.com/docs/font-feature-settings) - [letter-spacing](https://tailwindcss.com/docs/letter-spacing) - [line-clamp](https://tailwindcss.com/docs/line-clamp) - [line-height](https://tailwindcss.com/docs/line-height) - [list-style-image](https://tailwindcss.com/docs/list-style-image) - [list-style-position](https://tailwindcss.com/docs/list-style-position) - [list-style-type](https://tailwindcss.com/docs/list-style-type) - [text-align](https://tailwindcss.com/docs/text-align) - [color](https://tailwindcss.com/docs/color) - [text-decoration-line](https://tailwindcss.com/docs/text-decoration-line) - [text-decoration-color](https://tailwindcss.com/docs/text-decoration-color) - [text-decoration-style](https://tailwindcss.com/docs/text-decoration-style) - [text-decoration-thickness](https://tailwindcss.com/docs/text-decoration-thickness) - [text-underline-offset](https://tailwindcss.com/docs/text-underline-offset) - [text-transform](https://tailwindcss.com/docs/text-transform) - [text-overflow](https://tailwindcss.com/docs/text-overflow) - [text-wrap](https://tailwindcss.com/docs/text-wrap) - [text-indent](https://tailwindcss.com/docs/text-indent) - [vertical-align](https://tailwindcss.com/docs/vertical-align) - [white-space](https://tailwindcss.com/docs/white-space) - [word-break](https://tailwindcss.com/docs/word-break) - [overflow-wrap](https://tailwindcss.com/docs/overflow-wrap) - [hyphens](https://tailwindcss.com/docs/hyphens) - [content](https://tailwindcss.com/docs/content) ### Backgrounds - [background-attachment](https://tailwindcss.com/docs/background-attachment) - [background-clip](https://tailwindcss.com/docs/background-clip) - [background-color](https://tailwindcss.com/docs/background-color) - [background-image](https://tailwindcss.com/docs/background-image) - [background-origin](https://tailwindcss.com/docs/background-origin) - [background-position](https://tailwindcss.com/docs/background-position) - [background-repeat](https://tailwindcss.com/docs/background-repeat) - [background-size](https://tailwindcss.com/docs/background-size) ### Borders - [border-radius](https://tailwindcss.com/docs/border-radius) - [border-width](https://tailwindcss.com/docs/border-width) - [border-color](https://tailwindcss.com/docs/border-color) - [border-style](https://tailwindcss.com/docs/border-style) - [outline-width](https://tailwindcss.com/docs/outline-width) - [outline-color](https://tailwindcss.com/docs/outline-color) - [outline-style](https://tailwindcss.com/docs/outline-style) - [outline-offset](https://tailwindcss.com/docs/outline-offset) ### Effects - [box-shadow](https://tailwindcss.com/docs/box-shadow) - [text-shadow](https://tailwindcss.com/docs/text-shadow) - [opacity](https://tailwindcss.com/docs/opacity) - [mix-blend-mode](https://tailwindcss.com/docs/mix-blend-mode) - [background-blend-mode](https://tailwindcss.com/docs/background-blend-mode) - [mask-clip](https://tailwindcss.com/docs/mask-clip) - [mask-composite](https://tailwindcss.com/docs/mask-composite) - [mask-image](https://tailwindcss.com/docs/mask-image) - [mask-mode](https://tailwindcss.com/docs/mask-mode) - [mask-origin](https://tailwindcss.com/docs/mask-origin) - [mask-position](https://tailwindcss.com/docs/mask-position) - [mask-repeat](https://tailwindcss.com/docs/mask-repeat) - [mask-size](https://tailwindcss.com/docs/mask-size) - [mask-type](https://tailwindcss.com/docs/mask-type) ### Filters - [filter](https://tailwindcss.com/docs/filter) - [blur](https://tailwindcss.com/docs/filter-blur) - [brightness](https://tailwindcss.com/docs/filter-brightness) - [contrast](https://tailwindcss.com/docs/filter-contrast) - [drop-shadow](https://tailwindcss.com/docs/filter-drop-shadow) - [grayscale](https://tailwindcss.com/docs/filter-grayscale) - [hue-rotate](https://tailwindcss.com/docs/filter-hue-rotate) - [invert](https://tailwindcss.com/docs/filter-invert) - [saturate](https://tailwindcss.com/docs/filter-saturate) - [sepia](https://tailwindcss.com/docs/filter-sepia) - [backdrop-filter](https://tailwindcss.com/docs/backdrop-filter) - [blur](https://tailwindcss.com/docs/backdrop-filter-blur) - [brightness](https://tailwindcss.com/docs/backdrop-filter-brightness) - [contrast](https://tailwindcss.com/docs/backdrop-filter-contrast) - [grayscale](https://tailwindcss.com/docs/backdrop-filter-grayscale) - [hue-rotate](https://tailwindcss.com/docs/backdrop-filter-hue-rotate) - [invert](https://tailwindcss.com/docs/backdrop-filter-invert) - [opacity](https://tailwindcss.com/docs/backdrop-filter-opacity) - [saturate](https://tailwindcss.com/docs/backdrop-filter-saturate) - [sepia](https://tailwindcss.com/docs/backdrop-filter-sepia) ### Tables - [border-collapse](https://tailwindcss.com/docs/border-collapse) - [border-spacing](https://tailwindcss.com/docs/border-spacing) - [table-layout](https://tailwindcss.com/docs/table-layout) - [caption-side](https://tailwindcss.com/docs/caption-side) ### Transitions & Animation - [transition-property](https://tailwindcss.com/docs/transition-property) - [transition-behavior](https://tailwindcss.com/docs/transition-behavior) - [transition-duration](https://tailwindcss.com/docs/transition-duration) - [transition-timing-function](https://tailwindcss.com/docs/transition-timing-function) - [transition-delay](https://tailwindcss.com/docs/transition-delay) - [animation](https://tailwindcss.com/docs/animation) ### Transforms - [backface-visibility](https://tailwindcss.com/docs/backface-visibility) - [perspective](https://tailwindcss.com/docs/perspective) - [perspective-origin](https://tailwindcss.com/docs/perspective-origin) - [rotate](https://tailwindcss.com/docs/rotate) - [scale](https://tailwindcss.com/docs/scale) - [skew](https://tailwindcss.com/docs/skew) - [transform](https://tailwindcss.com/docs/transform) - [transform-origin](https://tailwindcss.com/docs/transform-origin) - [transform-style](https://tailwindcss.com/docs/transform-style) - [translate](https://tailwindcss.com/docs/translate) ### Interactivity - [accent-color](https://tailwindcss.com/docs/accent-color) - [appearance](https://tailwindcss.com/docs/appearance) - [caret-color](https://tailwindcss.com/docs/caret-color) - [color-scheme](https://tailwindcss.com/docs/color-scheme) - [cursor](https://tailwindcss.com/docs/cursor) - [field-sizing](https://tailwindcss.com/docs/field-sizing) - [pointer-events](https://tailwindcss.com/docs/pointer-events) - [resize](https://tailwindcss.com/docs/resize) - [scroll-behavior](https://tailwindcss.com/docs/scroll-behavior) - [scroll-margin](https://tailwindcss.com/docs/scroll-margin) - [scroll-padding](https://tailwindcss.com/docs/scroll-padding) - [scroll-snap-align](https://tailwindcss.com/docs/scroll-snap-align) - [scroll-snap-stop](https://tailwindcss.com/docs/scroll-snap-stop) - [scroll-snap-type](https://tailwindcss.com/docs/scroll-snap-type) - [touch-action](https://tailwindcss.com/docs/touch-action) - [user-select](https://tailwindcss.com/docs/user-select) - [will-change](https://tailwindcss.com/docs/will-change) ### SVG - [fill](https://tailwindcss.com/docs/fill) - [stroke](https://tailwindcss.com/docs/stroke) - [stroke-width](https://tailwindcss.com/docs/stroke-width) ### Accessibility - [forced-color-adjust](https://tailwindcss.com/docs/forced-color-adjust) Core concepts # Detecting classes in source files Understanding and customizing how Tailwind scans your source files. ## [Overview](https://tailwindcss.com/docs/detecting-classes-in-source-files#overview) Tailwind works by scanning your project for utility classes, then generating all of the necessary CSS based on the classes you've actually used. This makes sure your CSS is as small as possible, and is also what makes features like [arbitrary values](https://tailwindcss.com/docs/adding-custom-styles#using-arbitrary-values) possible. ### [How classes are detected](https://tailwindcss.com/docs/detecting-classes-in-source-files#how-classes-are-detected) Tailwind treats all of your source files as plain text, and doesn't attempt to actually parse your files as code in any way. Instead it just looks for any tokens in your file that could be classes based on which characters Tailwind is expecting in class names: JSX ``` export function Button({ color, children }) { const colors = { black: "bg-black text-white", blue: "bg-blue-500 text-white", white: "bg-white text-black", }; return ( <button className={`${colors[color]} rounded-full px-2 py-1.5 font-sans text-sm/6 font-medium shadow`}> {children} </button> );} ``` Then it tries to generate the CSS for all of these tokens, throwing away any tokens that don't map to a utility class the framework knows about. ### [Dynamic class names](https://tailwindcss.com/docs/detecting-classes-in-source-files#dynamic-class-names) Since Tailwind scans your source files as plain text, it has no way of understanding string concatenation or interpolation in the programming language you're using. Don't construct class names dynamically HTML ``` <div class="text-{{ error ? 'red' : 'green' }}-600"></div> ``` In the example above, the strings `text-red-600` and `text-green-600` do not exist, so Tailwind will not generate those classes. Instead, make sure any class names you’re using exist in full: Always use complete class names HTML ``` <div class="{{ error ? 'text-red-600' : 'text-green-600' }}"></div> ``` If you're using a component library like React or Vue, this means you shouldn't use props to dynamically construct classes: Don't use props to build class names dynamically JSX ``` function Button({ color, children }) { return <button className={`bg-${color}-600 hover:bg-${color}-500 ...`}>{children}</button>;} ``` Instead, map props to complete class names that are statically detectable at build-time: Always map props to static class names JSX ``` function Button({ color, children }) { const colorVariants = { blue: "bg-blue-600 hover:bg-blue-500", red: "bg-red-600 hover:bg-red-500", }; return <button className={`${colorVariants[color]} ...`}>{children}</button>;} ``` This has the added benefit of letting you map different prop values to different color shades for example: JSX ``` function Button({ color, children }) { const colorVariants = { blue: "bg-blue-600 hover:bg-blue-500 text-white", red: "bg-red-500 hover:bg-red-400 text-white", yellow: "bg-yellow-300 hover:bg-yellow-400 text-black", }; return <button className={`${colorVariants[color]} ...`}>{children}</button>;} ``` As long as you always use complete class names in your code, Tailwind will generate all of your CSS perfectly every time. ### [Which files are scanned](https://tailwindcss.com/docs/detecting-classes-in-source-files#which-files-are-scanned) Tailwind will scan every file in your project for class names, except in the following cases: - Files that are in your `.gitignore` file - Files in the `node_modules` directory - Binary files like images, videos, or zip files - CSS files - Common package manager lock files If you need to scan any files that Tailwind is ignoring by default, you can [explicitly register](https://tailwindcss.com/docs/detecting-classes-in-source-files#explicitly-registering-sources) those sources. ## [Explicitly registering sources](https://tailwindcss.com/docs/detecting-classes-in-source-files#explicitly-registering-sources) Use `@source` to explicitly register source paths relative to the stylesheet: CSS ``` @import "tailwindcss";@source "../node_modules/@acmecorp/ui-lib"; ``` This is especially useful when you need to scan an external library that is built with Tailwind, since dependencies are usually listed in your `.gitignore` file and ignored by Tailwind by default. ### [Setting your base path](https://tailwindcss.com/docs/detecting-classes-in-source-files#setting-your-base-path) Tailwind uses the current working directory as its starting point when scanning for class names by default. To set the base path for source detection explicitly, use the `source()` function when importing Tailwind in your CSS: CSS ``` @import "tailwindcss" source("../src"); ``` This can be useful when working with monorepos where your build commands run from the root of the monorepo instead of the root of each project. ### [Ignoring specific paths](https://tailwindcss.com/docs/detecting-classes-in-source-files#ignoring-specific-paths) Use `@source not` to ignore specific paths, relative to the stylesheet, when scanning for class names: CSS ``` @import "tailwindcss";@source not "../src/components/legacy"; ``` This is useful when you have large directories in your project that you know don't use Tailwind classes, like legacy components or third-party libraries. ### [Disabling automatic detection](https://tailwindcss.com/docs/detecting-classes-in-source-files#disabling-automatic-detection) Use `source(none)` to completely disable automatic source detection if you want to register all of your sources explicitly: CSS ``` @import "tailwindcss" source(none);@source "../admin";@source "../shared"; ``` This can be useful in projects that have multiple Tailwind stylesheets where you want to make sure each one only includes the classes each stylesheet needs. ## [Safelisting specific utilities](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-specific-utilities) If you need to make sure Tailwind generates certain class names that don’t exist in your content files, use `@source inline()` to force them to be generated: CSS ``` @import "tailwindcss";@source inline("underline"); ``` Generated CSS ``` .underline { text-decoration-line: underline;} ``` ### [Safelisting variants](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-variants) You can also use `@source inline()` to generate classes with variants. For example, to generate the `underline` class with hover and focus variants, add `{hover:,focus:,}` to the source input: CSS ``` @import "tailwindcss";@source inline("{hover:,focus:,}underline"); ``` Generated CSS ``` .underline { text-decoration-line: underline;}@media (hover: hover) { .hover\:underline:hover { text-decoration-line: underline; }}@media (focus: focus) { .focus\:underline:focus { text-decoration-line: underline; }} ``` ### [Safelisting with ranges](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-with-ranges) The source input is [brace expanded](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html), so you can generate multiple classes at once. For example, to generate all the red background colors with hover variants, use a range: CSS ``` @import "tailwindcss";@source inline("{hover:,}bg-red-{50,{100..900..100},950}"); ``` Generated CSS ``` .bg-red-50 { background-color: var(--color-red-50);}.bg-red-100 { background-color: var(--color-red-100);}.bg-red-200 { background-color: var(--color-red-200);}/* ... */.bg-red-800 { background-color: var(--color-red-800);}.bg-red-900 { background-color: var(--color-red-900);}.bg-red-950 { background-color: var(--color-red-950);}@media (hover: hover) { .hover\:bg-red-50:hover { background-color: var(--color-red-50); } /* ... */ .hover\:bg-red-950:hover { background-color: var(--color-red-950); }} ``` This generates red background colors from 100 to 900 in increments of 100, along with the first and last shades of 50 and 950. It also adds the `hover:` variant for each of those classes. ### [Explicitly excluding classes](https://tailwindcss.com/docs/detecting-classes-in-source-files#explicitly-excluding-classes) Use `@source not inline()` to prevent specific classes from being generated, even if they are detected in your source files: CSS ``` @import "tailwindcss";@source not inline("{hover:,focus:,}bg-red-{50,{100..900..100},950}"); ``` This will explicitly exclude the red background utilities, along with their hover and focus variants, from being generated. [Adding custom styles](https://tailwindcss.com/docs/adding-custom-styles) [Functions and directives](https://tailwindcss.com/docs/functions-and-directives) ### On this page - [Overview](https://tailwindcss.com/docs/detecting-classes-in-source-files#overview) - [How classes are detected](https://tailwindcss.com/docs/detecting-classes-in-source-files#how-classes-are-detected) - [Dynamic class names](https://tailwindcss.com/docs/detecting-classes-in-source-files#dynamic-class-names) - [Which files are scanned](https://tailwindcss.com/docs/detecting-classes-in-source-files#which-files-are-scanned) - [Explicitly registering sources](https://tailwindcss.com/docs/detecting-classes-in-source-files#explicitly-registering-sources) - [Setting your base path](https://tailwindcss.com/docs/detecting-classes-in-source-files#setting-your-base-path) - [Ignoring specific paths](https://tailwindcss.com/docs/detecting-classes-in-source-files#ignoring-specific-paths) - [Disabling automatic detection](https://tailwindcss.com/docs/detecting-classes-in-source-files#disabling-automatic-detection) - [Safelisting specific utilities](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-specific-utilities) - [Safelisting variants](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-variants) - [Safelisting with ranges](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-with-ranges) - [Explicitly excluding classes](https://tailwindcss.com/docs/detecting-classes-in-source-files#explicitly-excluding-classes) [![Refactoring UI](https://tailwindcss.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fbook-promo.3012c0f6.png&w=256&q=75)From the creators of Tailwind CSSMake your ideas look awesome, without relying on a designer.“This is the survival kit I wish I had when I started building apps.” Derrick Reimer, SavvyCal](https://www.refactoringui.com/?ref=sidebar) ### Tailwind CSS - [Documentation](https://tailwindcss.com/docs) - [Playground](https://play.tailwindcss.com/) - [Blog](https://tailwindcss.com/blog) - [Showcase](https://tailwindcss.com/showcase) - [Sponsor](https://tailwindcss.com/sponsor) ### Resources - [Refactoring UI](https://www.refactoringui.com/) - [Headless UI](https://headlessui.com/) - [Heroicons](https://heroicons.com/) - [Hero Patterns](https://heropatterns.com/) ### [Tailwind Plus](https://tailwindcss.com/plus?ref=footer) - [UI Blocks](https://tailwindcss.com/plus/ui-blocks?ref=footer) - [Templates](https://tailwindcss.com/plus/templates?ref=footer) - [UI Kit](https://tailwindcss.com/plus/ui-kit?ref=footer) ### Community - [GitHub](https://github.com/tailwindlabs/tailwindcss) - [Discord](https://tailwindcss.com/sponsor#insiders) - [X](https://x.com/tailwindcss) ### Tailwind CSS - [Documentation](https://tailwindcss.com/docs) - [Playground](https://play.tailwindcss.com/) - [Blog](https://tailwindcss.com/blog) - [Showcase](https://tailwindcss.com/showcase) - [Sponsor](https://tailwindcss.com/sponsor) ### [Tailwind Plus](https://tailwindcss.com/plus?ref=footer) - [UI Blocks](https://tailwindcss.com/plus/ui-blocks?ref=footer) - [Templates](https://tailwindcss.com/plus/templates?ref=footer) - [UI Kit](https://tailwindcss.com/plus/ui-kit?ref=footer) ### Resources - [Refactoring UI](https://www.refactoringui.com/) - [Headless UI](https://headlessui.com/) - [Heroicons](https://heroicons.com/) - [Hero Patterns](https://heropatterns.com/) ### Community - [GitHub](https://github.com/tailwindlabs/tailwindcss) - [Discord](https://tailwindcss.com/sponsor#insiders) - [X](https://x.com/tailwindcss) Copyright © 2026 Tailwind Labs Inc.·[Trademark Policy](https://tailwindcss.com/brand)
Readable Markdown
Understanding and customizing how Tailwind scans your source files. ## [Overview](https://tailwindcss.com/docs/detecting-classes-in-source-files#overview) Tailwind works by scanning your project for utility classes, then generating all of the necessary CSS based on the classes you've actually used. This makes sure your CSS is as small as possible, and is also what makes features like [arbitrary values](https://tailwindcss.com/docs/adding-custom-styles#using-arbitrary-values) possible. ### [How classes are detected](https://tailwindcss.com/docs/detecting-classes-in-source-files#how-classes-are-detected) Tailwind treats all of your source files as plain text, and doesn't attempt to actually parse your files as code in any way. Instead it just looks for any tokens in your file that could be classes based on which characters Tailwind is expecting in class names: JSX ``` export function Button({ color, children }) { const colors = { black: "bg-black text-white", blue: "bg-blue-500 text-white", white: "bg-white text-black", }; return ( <button className={`${colors[color]} rounded-full px-2 py-1.5 font-sans text-sm/6 font-medium shadow`}> {children} </button> );} ``` Then it tries to generate the CSS for all of these tokens, throwing away any tokens that don't map to a utility class the framework knows about. ### [Dynamic class names](https://tailwindcss.com/docs/detecting-classes-in-source-files#dynamic-class-names) Since Tailwind scans your source files as plain text, it has no way of understanding string concatenation or interpolation in the programming language you're using. Don't construct class names dynamically HTML ``` <div class="text-{{ error ? 'red' : 'green' }}-600"></div> ``` In the example above, the strings `text-red-600` and `text-green-600` do not exist, so Tailwind will not generate those classes. Instead, make sure any class names you’re using exist in full: Always use complete class names HTML ``` <div class="{{ error ? 'text-red-600' : 'text-green-600' }}"></div> ``` If you're using a component library like React or Vue, this means you shouldn't use props to dynamically construct classes: Don't use props to build class names dynamically JSX ``` function Button({ color, children }) { return <button className={`bg-${color}-600 hover:bg-${color}-500 ...`}>{children}</button>;} ``` Instead, map props to complete class names that are statically detectable at build-time: Always map props to static class names JSX ``` function Button({ color, children }) { const colorVariants = { blue: "bg-blue-600 hover:bg-blue-500", red: "bg-red-600 hover:bg-red-500", }; return <button className={`${colorVariants[color]} ...`}>{children}</button>;} ``` This has the added benefit of letting you map different prop values to different color shades for example: JSX ``` function Button({ color, children }) { const colorVariants = { blue: "bg-blue-600 hover:bg-blue-500 text-white", red: "bg-red-500 hover:bg-red-400 text-white", yellow: "bg-yellow-300 hover:bg-yellow-400 text-black", }; return <button className={`${colorVariants[color]} ...`}>{children}</button>;} ``` As long as you always use complete class names in your code, Tailwind will generate all of your CSS perfectly every time. ### [Which files are scanned](https://tailwindcss.com/docs/detecting-classes-in-source-files#which-files-are-scanned) Tailwind will scan every file in your project for class names, except in the following cases: - Files that are in your `.gitignore` file - Files in the `node_modules` directory - Binary files like images, videos, or zip files - CSS files - Common package manager lock files If you need to scan any files that Tailwind is ignoring by default, you can [explicitly register](https://tailwindcss.com/docs/detecting-classes-in-source-files#explicitly-registering-sources) those sources. ## [Explicitly registering sources](https://tailwindcss.com/docs/detecting-classes-in-source-files#explicitly-registering-sources) Use `@source` to explicitly register source paths relative to the stylesheet: CSS ``` @import "tailwindcss";@source "../node_modules/@acmecorp/ui-lib"; ``` This is especially useful when you need to scan an external library that is built with Tailwind, since dependencies are usually listed in your `.gitignore` file and ignored by Tailwind by default. ### [Setting your base path](https://tailwindcss.com/docs/detecting-classes-in-source-files#setting-your-base-path) Tailwind uses the current working directory as its starting point when scanning for class names by default. To set the base path for source detection explicitly, use the `source()` function when importing Tailwind in your CSS: CSS ``` @import "tailwindcss" source("../src"); ``` This can be useful when working with monorepos where your build commands run from the root of the monorepo instead of the root of each project. ### [Ignoring specific paths](https://tailwindcss.com/docs/detecting-classes-in-source-files#ignoring-specific-paths) Use `@source not` to ignore specific paths, relative to the stylesheet, when scanning for class names: CSS ``` @import "tailwindcss";@source not "../src/components/legacy"; ``` This is useful when you have large directories in your project that you know don't use Tailwind classes, like legacy components or third-party libraries. ### [Disabling automatic detection](https://tailwindcss.com/docs/detecting-classes-in-source-files#disabling-automatic-detection) Use `source(none)` to completely disable automatic source detection if you want to register all of your sources explicitly: CSS ``` @import "tailwindcss" source(none);@source "../admin";@source "../shared"; ``` This can be useful in projects that have multiple Tailwind stylesheets where you want to make sure each one only includes the classes each stylesheet needs. ## [Safelisting specific utilities](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-specific-utilities) If you need to make sure Tailwind generates certain class names that don’t exist in your content files, use `@source inline()` to force them to be generated: CSS ``` @import "tailwindcss";@source inline("underline"); ``` Generated CSS ``` .underline { text-decoration-line: underline;} ``` ### [Safelisting variants](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-variants) You can also use `@source inline()` to generate classes with variants. For example, to generate the `underline` class with hover and focus variants, add `{hover:,focus:,}` to the source input: CSS ``` @import "tailwindcss";@source inline("{hover:,focus:,}underline"); ``` Generated CSS ``` .underline { text-decoration-line: underline;}@media (hover: hover) { .hover\:underline:hover { text-decoration-line: underline; }}@media (focus: focus) { .focus\:underline:focus { text-decoration-line: underline; }} ``` ### [Safelisting with ranges](https://tailwindcss.com/docs/detecting-classes-in-source-files#safelisting-with-ranges) The source input is [brace expanded](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html), so you can generate multiple classes at once. For example, to generate all the red background colors with hover variants, use a range: CSS ``` @import "tailwindcss";@source inline("{hover:,}bg-red-{50,{100..900..100},950}"); ``` Generated CSS ``` .bg-red-50 { background-color: var(--color-red-50);}.bg-red-100 { background-color: var(--color-red-100);}.bg-red-200 { background-color: var(--color-red-200);}/* ... */.bg-red-800 { background-color: var(--color-red-800);}.bg-red-900 { background-color: var(--color-red-900);}.bg-red-950 { background-color: var(--color-red-950);}@media (hover: hover) { .hover\:bg-red-50:hover { background-color: var(--color-red-50); } /* ... */ .hover\:bg-red-950:hover { background-color: var(--color-red-950); }} ``` This generates red background colors from 100 to 900 in increments of 100, along with the first and last shades of 50 and 950. It also adds the `hover:` variant for each of those classes. ### [Explicitly excluding classes](https://tailwindcss.com/docs/detecting-classes-in-source-files#explicitly-excluding-classes) Use `@source not inline()` to prevent specific classes from being generated, even if they are detected in your source files: CSS ``` @import "tailwindcss";@source not inline("{hover:,focus:,}bg-red-{50,{100..900..100},950}"); ``` This will explicitly exclude the red background utilities, along with their hover and focus variants, from being generated.
Shard59 (laksa)
Root Hash16242711095379765659
Unparsed URLcom,tailwindcss!/docs/detecting-classes-in-source-files s443