Episode 1 — Fundamentals / 1.11 — CSS Frameworks TailwindCSS and Bootstrap

1.11 — CSS Frameworks (TailwindCSS & Bootstrap): Quick Revision

Compact cheat sheet. Print-friendly.

How to use this material (instructions)

  1. Skim top-to-bottom in one pass before interviews or exams.
  2. If a row feels fuzzy — reopen the matching lesson: README.md1.11.a1.11.h.
  3. Drills1.11-Exercise-Questions.md.
  4. Polished answers1.11-Interview-Questions.md.

1.11.a Introduction to CSS Frameworks

What CSS Frameworks Provide

FeatureDescription
Ready-made stylesButtons, forms, typography — pre-built
Layout systemsGrids, flexbox helpers for responsive design
Design tokensConsistent spacing, colors, breakpoints
ConventionsTeam-wide standards to reduce bikeshedding

Categories

CategoryExampleCore idea
Utility-firstTailwindCSSSmall atomic classes composed in HTML
Component-basedBootstrapPre-styled widgets assembled with class names
CSS-in-JSstyled-componentsStyles in JavaScript, scoped per component
HeadlessRadix UIBehavior only, BYO styles

Trade-offs

BenefitCost
SpeedLearning curve
ConsistencyBundle size
Responsive by defaultDesign uniformity
CommunityDependency risk

1.11.b Utility-First vs Component-Based

Side-by-side

AspectUtility-firstComponent-based
MarkupLong class listsShort class names
CSS outputTiny (purged)Larger (full library)
Design freedomHighMedium
Pre-built componentsNoneDozens
NamingNo naming neededLearn component API
ConsistencyVia config/disciplineAutomatic

Same button, two ways

<!-- Tailwind -->
<button class="bg-blue-600 text-white py-2 px-4 rounded hover:bg-blue-700">Save</button>

<!-- Bootstrap -->
<button class="btn btn-primary">Save</button>

1.11.c TailwindCSS Setup & Basics

Setup Commands

npm install -D tailwindcss
npx tailwindcss init          # creates tailwind.config.js
/* CSS entry file */
@tailwind base;
@tailwind components;
@tailwind utilities;

Essential Config

module.exports = {
  content: ["./src/**/*.{html,js,jsx,tsx}"],
  theme: { extend: {} },
  plugins: [],
};

Core Utility Classes

UtilityCSS
flexdisplay: flex
items-centeralign-items: center
justify-betweenjustify-content: space-between
p-4padding: 1rem
m-2margin: 0.5rem
gap-4gap: 1rem
bg-blue-500background-color: #3b82f6
text-whitecolor: #fff
text-lgfont-size: 1.125rem
font-boldfont-weight: 700
rounded-lgborder-radius: 0.5rem
shadow-mdmedium box shadow
w-fullwidth: 100%
hiddendisplay: none
blockdisplay: block

Responsive Prefixes (mobile-first)

PrefixMin-width
(none)0 (all)
sm:640px
md:768px
lg:1024px
xl:1280px
2xl:1536px

State Variants

VariantWhen
hover:Mouse over
focus:Has focus
active:Being clicked
disabled:Disabled
dark:Dark mode active
group-hover:Parent hovered

Spacing Scale

Classrempx (at 16px root)
-10.25rem4px
-20.5rem8px
-41rem16px
-61.5rem24px
-82rem32px
-123rem48px
-164rem64px

1.11.d Building with Tailwind

Layout Patterns

<!-- Flex row with centered items -->
<div class="flex items-center justify-between gap-4">...</div>

<!-- Responsive grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">...</div>

<!-- Show/hide by breakpoint -->
<div class="hidden md:block">Desktop only</div>
<div class="block md:hidden">Mobile only</div>

Dark Mode

// tailwind.config.js
module.exports = { darkMode: "class" }; // or "media"
<div class="bg-white dark:bg-gray-900 text-gray-900 dark:text-white">
ModeActivation
"media"OS prefers-color-scheme
"class"class="dark" on parent element

Component Reuse

Prefer framework components (React, Vue) over @apply. Use @apply only for global styles you can't abstract into components.


1.11.e Introduction to Bootstrap

Installation

MethodHow
CDN<link> + <script> tags — no build step
npmnpm install bootstrap → import in JS
SASSnpm install bootstrap@import with variable overrides

Grid Basics

.container  →  centers content, sets max-width
  └── .row  →  flex container
       └── .col-*  →  column width (1–12)

Breakpoints

InfixMin-width
(none)0
sm576px
md768px
lg992px
xl1200px
xxl1400px

1.11.f Bootstrap Grid & Components

Grid Patterns

<!-- Two equal columns -->
<div class="row"><div class="col-6">A</div><div class="col-6">B</div></div>

<!-- Responsive: full → half → third -->
<div class="col-12 col-md-6 col-lg-4">...</div>

<!-- Centered column with offset -->
<div class="col-md-6 offset-md-3">Centered</div>

Key Components

ComponentClasses
Buttonbtn btn-primary, btn-outline-danger, btn-lg
Cardcard, card-body, card-title, card-text
Navbarnavbar navbar-expand-lg, navbar-brand, nav-link
Modalmodal, modal-dialog, modal-content, modal-header/body/footer
Alertalert alert-success, alert-dismissible
Formform-control, form-label, form-check, form-select
Badgebadge bg-primary, rounded-pill

Gutter Classes

ClassAxis
g-4Both
gx-4Horizontal
gy-4Vertical

1.11.g Customizing Bootstrap

SASS Variable Override Pattern

// 1. Define overrides (BEFORE import)
$primary: #6366f1;
$border-radius: 0.75rem;

// 2. Import Bootstrap (uses !default, picks up your values)
@import "bootstrap/scss/bootstrap";

Cherry-Picking (Reduce Bundle)

@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/reboot";
@import "bootstrap/scss/grid";
@import "bootstrap/scss/buttons";
@import "bootstrap/scss/utilities/api";

Bundle Size Reduction

TechniqueEffect
Cherry-pick imports50–70% smaller
PurgeCSSRemoves unused classes
Skip JS bundleNo JS if not using interactive components
Minify + gzip~230 KB → ~25 KB

1.11.h TailwindCSS vs Bootstrap — Comparison

Master Comparison Table

DimensionTailwindCSSBootstrap
PhilosophyUtility-firstComponent-based
Production CSS~5–15 KB gzipped~25 KB gzipped
ComponentsNone built-in25+ ready-made
JavaScriptNoneBundle.js included
Customizationtailwind.config.jsSASS variables
Dark modedark: variantdata-bs-theme / CSS vars
Build stepRequired (PostCSS)Optional (CDN works)
Design freedomVery highMedium
Learning curveMemorize classesLearn component API

When to Use Each

TailwindBootstrap
Custom design systemRapid prototyping / MVP
Modern stack (React/Vue)Admin panels, internal tools
Small bundle priorityTeam needs pre-built components
Long-term projectNo build step available
Pixel-perfect design matchEnterprise / legacy project

Ecosystem

TailwindBootstrap
Headless UIReact-Bootstrap
shadcn/uiNG Bootstrap
DaisyUIBootswatch
Tailwind UI (premium)Bootstrap Icons

One-liner definitions

TermOne-liner
CSS frameworkPre-written CSS providing styles, layout, and design tokens for faster development.
Utility-firstSmall, single-purpose classes composed directly in HTML markup.
Component-basedPre-styled, named components assembled with short class names.
TailwindCSSUtility-first CSS framework; compose designs with atomic classes like flex, p-4, bg-blue-500.
BootstrapComponent-based CSS framework; pre-built widgets + 12-column grid + JS plugins.
PurgingBuild-time removal of unused CSS classes to minimize production bundle.
JITJust-In-Time compilation; generates only the CSS for classes you actually use.
@applyTailwind directive to extract utility patterns into custom CSS classes.
!defaultSASS keyword meaning "use this value unless already defined" — enables overrides.
Design tokensNamed values (colors, spacing, fonts) that define a design system's visual language.
12-column gridBootstrap's flexbox layout system; 12 divides into halves, thirds, quarters, sixths.
Content pathsTailwind config array that tells the build tool which files to scan for class names.
Mobile-firstBase styles target small screens; larger-screen styles are added with breakpoint prefixes.
Breakpoint prefixResponsive class modifier (sm:, md:, lg:) applying styles at min-width and above.
State variantClass modifier (hover:, focus:, active:) applying styles on interaction state.
Cherry-pickingImporting only specific SASS partials to reduce Bootstrap's output CSS.
Utilities APIBootstrap 5 feature for generating custom utility classes via SASS maps.
Headless UIAccessible, unstyled component library designed to pair with Tailwind.
shadcn/uiCopy-paste React component library built with Tailwind + Radix primitives.

Master workflow — Choosing a CSS Framework

  1. Learn CSS first — understand box model, flexbox, grid, cascade.
  2. Identify project needs — custom design? rapid prototype? team skills?
  3. Pick one framework — Tailwind for custom, Bootstrap for pre-built.
  4. Configure — Tailwind: tailwind.config.js. Bootstrap: SASS variables.
  5. Build responsive — both are mobile-first; use breakpoint prefixes/classes.
  6. Optimize bundle — Tailwind: automatic purging. Bootstrap: cherry-pick + PurgeCSS.
  7. Extract patterns — Tailwind: framework components. Bootstrap: SASS mixins + custom classes.
  8. Ship — verify production CSS is minimal; test responsiveness across breakpoints.

End of 1.11 quick revision.