📖 Scenario: You want to start a new project using Tailwind CSS. You need to decide between using the CDN for quick setup or installing Tailwind with a build tool for full power. You will try both approaches to understand the difference.
🎯 Goal: Set up Tailwind CSS using both the CDN method and the build tool method, then compare the output to understand why production projects use build tools.
📋 What You'll Learn
Create an HTML page using Tailwind via CDN
Set up Tailwind with npm and the CLI build tool
Compare the generated CSS file sizes
Demonstrate a feature only available with build tools
💡 Why This Matters
🌍 Real World
Every production Tailwind project uses build tools. CDN is only for learning and quick demos.
💼 Career
Interviewers expect you to know the difference and when to use each approach.
Progress0 / 4 steps
1
Create HTML page with Tailwind CDN
Create an index-cdn.html file that loads Tailwind CSS from the CDN and uses a few utility classes to style a heading and button.
Tailwind
Hint
Add <script src="https://cdn.tailwindcss.com"></script> in the head section.
2
Initialize Tailwind with npm
In a new project folder, run npm init -y, install Tailwind CSS as a dev dependency, and generate the config file with npx tailwindcss init.
Tailwind
Hint
Use npm install -D tailwindcss to install as a dev dependency, then npx tailwindcss init to create tailwind.config.js.
3
Configure content paths and create input CSS
Update tailwind.config.js to scan your HTML files, and create an input.css file with the three Tailwind directives.
Tailwind
Hint
Set content to ['./*.html'] so Tailwind scans your HTML files for used classes.
4
Build and compare output sizes
Run the Tailwind CLI to compile your CSS, then create the same styled page using the build output instead of the CDN. Add a custom color using theme.extend to demonstrate a build-tool-only feature.
Tailwind
Hint
Add a colors object inside extend with your custom color name and hex value.
Practice
(1/5)
1. Which of the following is a key advantage of using Tailwind via CDN instead of a build tool?
easy
A. It produces a smaller, optimized CSS file for production.
B. It automatically removes unused CSS classes.
C. It allows custom configuration of Tailwind classes.
D. It requires no setup and works immediately for quick prototypes.
Solution
Step 1: Understand CDN usage context
Using Tailwind via CDN means you just add a link to your HTML and start using styles immediately without setup.
Step 2: Compare with build tool features
Build tools require setup but optimize CSS size and allow customization, unlike CDN which loads all styles.
Final Answer:
It requires no setup and works immediately for quick prototypes. -> Option D
Quick Check:
CDN = No setup, fast start [OK]
Hint: CDN means no setup, build tool means setup and optimization [OK]
Common Mistakes:
Thinking CDN optimizes CSS size
Assuming CDN allows custom config
Believing CDN removes unused styles
2. Which HTML tag correctly includes Tailwind CSS via CDN?
easy
A.
B.
C.
D.
Solution
Step 1: Identify correct CDN inclusion method
Tailwind CDN is included via a script tag that loads the Tailwind JavaScript to inject styles dynamically.
Step 2: Eliminate incorrect tags
Link tag is for CSS files, but Tailwind CDN uses a script. Style tag cannot have src attribute. Custom tags like <tailwind> are invalid.
Final Answer:
<script src="https://cdn.tailwindcss.com"></script> -> Option A
Quick Check:
Tailwind CDN uses <script> tag [OK]
Hint: Tailwind CDN loads via script tag, not link [OK]