We use Tailwind CSS to style websites quickly. You can add Tailwind either by linking to a CDN or by using a build tool. Each way has its own benefits and fits different needs.
CDN vs build tool comparison in Tailwind
/* Using CDN */ <link href="https://cdn.tailwindcss.com" rel="stylesheet"> /* Using Build Tool (example with npm and PostCSS) */ npm install -D tailwindcss postcss autoprefixer npx tailwindcss init /* In your CSS file */ @tailwind base; @tailwind components; @tailwind utilities;
CDN method is simple and fast but includes all Tailwind styles.
Build tool method requires setup but creates smaller, optimized CSS.
<link href="https://cdn.tailwindcss.com" rel="stylesheet">
/* tailwind.config.js */ module.exports = { content: ['./src/**/*.{html,js}'], theme: { extend: {}, }, plugins: [], };
@tailwind base; @tailwind components; @tailwind utilities;
This example shows how you can use Tailwind CSS either by linking a CDN or by setting up a build tool. The CDN method is fast but loads all styles. The build tool method takes time to set up but creates a smaller CSS file with only the styles you use.
/* Sample project setup comparison */ // Using CDN in HTML: // <html> // <head> // <script src="https://cdn.tailwindcss.com"></script> // </head> // <body> // <button class="bg-blue-500 text-white p-2 rounded">Click me</button> // </body> // </html> // Using Build Tool: // 1. Install Tailwind and dependencies // 2. Create tailwind.config.js with content paths // 3. Create styles.css with Tailwind directives // 4. Run build command to generate output.css // 5. Link output.css in HTML // Result: // CDN loads full Tailwind CSS (~3MB uncompressed), quick start. // Build tool generates small CSS with only used styles (~10KB), faster load. console.log("CDN method: quick start, full styles loaded."); console.log("Build tool method: setup needed, optimized CSS output.");
CDN is great for learning and small projects but not ideal for production due to large file size.
Build tools help keep your CSS small and fast by removing unused styles.
Using build tools allows customization like adding plugins or changing default themes.
CDN method is simple and fast but loads all Tailwind styles.
Build tool method requires setup but creates optimized, smaller CSS.
Choose CDN for quick prototypes and build tools for scalable projects.
Practice
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 DQuick Check:
CDN = No setup, fast start [OK]
- Thinking CDN optimizes CSS size
- Assuming CDN allows custom config
- Believing CDN removes unused styles
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 AQuick Check:
Tailwind CDN uses <script> tag [OK]
- Using <link> instead of <script>
- Adding src to <style> tag
- Using non-standard HTML tags
<script src="https://cdn.tailwindcss.com"></script> <div class="text-red-500 p-4">Hello</div>
What will be the color and padding of the div?
Solution
Step 1: Understand Tailwind CDN effect
The CDN loads all Tailwind styles, so all utility classes like text-red-500 and p-4 are available.Step 2: Interpret class meanings
text-red-500 sets text color to a shade of red, p-4 sets padding to 1rem (16px by default).Final Answer:
Text color red, padding 1rem -> Option BQuick Check:
text-red-500 + p-4 = red text + 1rem padding [OK]
- Assuming CDN misses some classes
- Confusing padding units
- Thinking CDN disables styles
Solution
Step 1: Understand build tool optimization
Build tools rely on PurgeCSS or content scanning to remove unused CSS classes and reduce file size.Step 2: Identify cause of large CSS
If PurgeCSS or content paths are not configured, the build tool includes all Tailwind styles, making the CSS large.Final Answer:
They forgot to configure PurgeCSS or content paths to remove unused styles. -> Option CQuick Check:
Missing purge config = large CSS [OK]
- Confusing CDN with build tool issues
- Assuming version affects CSS size directly
- Ignoring duplicate CSS includes
Solution
Step 1: Consider scalability and performance needs
For scalable apps, loading only needed CSS reduces file size and speeds up loading.Step 2: Evaluate Tailwind methods
Build tools with purge remove unused styles, creating small CSS files. CDN loads full CSS, which is large and inefficient for production.Step 3: Assess maintainability
Build tools allow custom config and integration with development workflow, improving maintainability.Final Answer:
Use a build tool with proper purge configuration to generate optimized CSS. -> Option AQuick Check:
Build tool + purge = optimized, scalable CSS [OK]
- Choosing CDN for production
- Manually including full CSS
- Using inline styles over utility classes
Ready to prove it?
Pass the test and this pattern moves unknown
