What if your CSS only included exactly what your page needs, nothing more?
Why JIT mode and on-demand generation in Tailwind? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you are building a website and you write CSS styles for every possible color, size, and layout you might need.
You create a huge CSS file with all these styles, even the ones you never use.
This big CSS file takes a long time to load and slows down your website.
Also, every time you want a new style, you have to add it manually and rebuild the whole CSS file.
JIT mode in Tailwind generates only the CSS styles you actually use in your HTML or code.
This means your CSS is small, loads fast, and updates instantly when you add new classes.
.text-red { color: red; }
.text-blue { color: blue; }
.text-green { color: green; }
/* many unused styles *//* Only .text-red generated if used in HTML */ .text-red { color: red; }
You can build fast, responsive websites without worrying about bloated CSS or slow rebuilds.
When you add a new button with a unique color class, Tailwind JIT instantly creates the needed CSS without waiting for a full rebuild.
Manual CSS grows large and slow.
JIT mode creates only what you use.
Faster builds and smaller CSS files.
Practice
Solution
Step 1: Understand JIT mode purpose
JIT mode creates CSS only for classes used in your files, not all possible classes.Step 2: Compare options
It generates only the CSS classes you actually use, making the site faster. matches this behavior; others describe incorrect or unrelated features.Final Answer:
It generates only the CSS classes you actually use, making the site faster. -> Option BQuick Check:
JIT mode = on-demand CSS generation [OK]
- Thinking JIT preloads all CSS
- Confusing JIT with disabling CSS
- Assuming JIT converts CSS to JS
Solution
Step 1: Identify correct config keys
Tailwind usesmode: 'jit'andcontentarray for files.Step 2: Check options
Only module.exports = { mode: 'jit', content: ['./src/**/*.{html,js}'] } uses correct keys and values; others use wrong keys or values.Final Answer:
module.exports = { mode: 'jit', content: ['./src/**/*.{html,js}'] } -> Option DQuick Check:
Config keys = mode and content [OK]
- Using wrong keys like jit or files
- Setting mode to 'fast' instead of 'jit'
- Using 'paths' instead of 'content'
module.exports = { mode: 'jit', content: ['./index.html'] }And this HTML:
<div class="bg-blue-500 p-4">Hello</div>
What CSS classes will be generated?
Solution
Step 1: Understand JIT CSS generation
JIT mode generates CSS only for classes found in the content files.Step 2: Check classes in HTML
Classesbg-blue-500andp-4appear, so their styles are generated.Final Answer:
Only styles for bg-blue-500 and p-4 classes. -> Option AQuick Check:
JIT generates CSS only for used classes [OK]
- Thinking all classes generate CSS
- Assuming JIT disables CSS generation
- Believing partial classes generate partial CSS
Solution
Step 1: Check JIT file watching setup
JIT mode watches files listed incontentto generate CSS on changes.Step 2: Identify cause of missing CSS
If edited files are not incontent, JIT won't generate CSS for new classes.Final Answer:
The content array in Tailwind config does not include the edited files. -> Option CQuick Check:
Content array must include all source files [OK]
- Forgetting to update content array
- Assuming JIT needs browser restart
- Thinking Tailwind lacks dynamic class support
bg-${color}-500 where color is a variable. How can you ensure Tailwind JIT generates the correct CSS?Solution
Step 1: Understand JIT limitation with dynamic classes
JIT cannot detect dynamic class names built from variables in code.Step 2: Provide all possible classes explicitly
You must list all possible class names in your files or use the safelist option in Tailwind config.Final Answer:
Add all possible classes like bg-red-500, bg-blue-500 explicitly in your files or safelist in config. -> Option AQuick Check:
Dynamic classes need explicit listing or safelist [OK]
- Expecting JIT to detect dynamic classes automatically
- Disabling JIT unnecessarily
- Using inline styles instead of Tailwind classes
