MODULE 04
Slide of 38
MODULE 04 • MODERN CSS

Tailwind CSS
Rapid Utility-First Styling

“Build modern, responsive interfaces directly in your markup”

Master utility classes, flexbox/grid layouts, responsive breakpoints, design tokens, and dark mode without writing raw CSS.
or press Space / →
HeroCard.tsx
<div className="p-6 bg-slate-900 border border-slate-800 rounded-xl shadow-xl flex items-center gap-4 hover:border-blue-500 transition-all">
  <div className="w-12 h-12 bg-blue-500/20 text-blue-400 rounded-lg flex items-center justify-center font-bold">
    TS
  </div>
  <div>
    <h3 className="text-lg font-bold text-white">Tailwind CSS</h3>
    <p className="text-sm text-slate-400">Utility-First Framework</p>
  </div>
</div>
OVERVIEW

Why Utility-First CSS?

How utility classes solve the classic pitfalls of traditional CSS files

Traditional CSS File Nightmare

You waste hours thinking of class names (.header-nav-card-item-inner). The CSS file grows infinitely because you fear deleting unused rules.

Result: Global naming collisions, style leakage, bloated CSS bundle.

Tailwind Utility-First Superpower

You style directly inside your markup with predefined constraints. Purges unused classes automatically for a tiny ~10kB production stylesheet.

No context switching between HTML and CSS files. Consistent spacing and colors.
SETUP

Configuration & Setup

Importing Tailwind directives into your project

src/app/globals.css
@import "tailwindcss";

@theme {
  --color-brand-primary: #2563eb;
  --color-brand-accent: #6366f1;
  --font-display: 'Plus Jakarta Sans', sans-serif;
}
bash — install tailwind
$pnpm add tailwindcss @tailwindcss/postcss postcss
+ tailwindcss 4.0.0
+ @tailwindcss/postcss 4.0.0
Packages installed successfully
UTILITIES

Sizing & Spacing System

Fixed mathematical scale for margins, paddings, and dimensions

Utility ClassCSS ValuePixel EquivalentUsage Example
p-1 / m-10.25rem4pxMicro gap, button tags
p-2 / m-20.5rem8pxSmall pill badges
p-3 / m-30.75rem12pxInput fields
p-4 / m-41rem16pxStandard card padding
p-5 / m-51.25rem20pxSection card containers
w-full / max-w-xl100% / 36remFull width with capResponsive containers
TYPOGRAPHY

Typography & Modern Colors

Pre-curated contrast and hierarchy

Typography Classes
<h1 className="text-3xl font-extrabold tracking-tight text-white">
  Main Heading
</h1>
<h2 className="text-xl font-bold text-slate-200 mt-2">
  Subtitle Heading
</h2>
<p className="text-sm text-slate-400 leading-relaxed mt-1">
  Descriptive paragraph text with balanced line height.
</p>
<span className=" text-xs text-blue-400">
  git status
</span>

Color Palette Rules

1. Backgrounds: bg-slate-900, bg-slate-950, bg-white

2. Text: text-slate-100 (primary), text-slate-400 (muted)

3. Accents: text-blue-400, bg-blue-500, border-blue-500/30

4. Borders: border-slate-800, border-slate-200

LAYOUT

Flexbox & CSS Grid in Action

Building responsive 2-column and 3-column card layouts

Responsive Grid Layout
{/* Responsive 1 col on mobile, 3 cols on desktop */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
  {features.map((item) => (
    <div 
      key={item.id}
      className="flex flex-col justify-between p-4 bg-slate-900 border border-slate-800 rounded-xl"
    >
      <div className="flex items-center justify-between">
        <span className="text-xs  text-blue-400">{item.tag}</span>
        <span className="text-xs text-slate-500">{item.date}</span>
      </div>
      <h3 className="text-base font-bold text-white mt-2">{item.title}</h3>
      <p className="text-sm text-slate-400 mt-1">{item.desc}</p>
    </div>
  ))}
</div>
RESPONSIVE

Mobile-First Breakpoint Architecture

Styles apply to mobile first, then scale up with prefixes

PrefixMinimum WidthCSS Media QueryTarget Device
(default)0px(mobile first)All smartphones
sm:640px@media (min-width: 640px)Large phones / small tablets
md:768px@media (min-width: 768px)Tablets / iPad
lg:1024px@media (min-width: 1024px)Laptops / Desktops
xl:1280px@media (min-width: 1280px)Large desktop monitors
Example: className="w-full md:w-1/2 lg:w-1/3" makes a column full width on phones, half width on tablets, and one third on desktop.
STATES

Interactive Hover, Focus & Active States

Polished micro-animations with transition utilities

Interactive Button Component
<button className="
  px-4 py-2 
  bg-blue-600 text-white font-bold text-sm 
  rounded-lg 
  hover:bg-blue-500 hover:shadow-lg hover:shadow-blue-500/25 
  focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-offset-2 focus:ring-offset-slate-950
  active:scale-95 
  transition-all duration-150 ease-out
">
  Submit Form 
</button>
Always include focus:ring-2 for keyboard accessibility and transition-all for smooth visual feedback.
DARK MODE

Tailwind Dark Mode Integration

Effortless dual-theme support using the dark: variant

Dual-Theme Card Example
<div className="
  bg-white dark:bg-slate-900 
  text-slate-900 dark:text-slate-100 
  border border-slate-200 dark:border-slate-800 
  rounded-xl p-5 shadow-sm
">
  <h3 className="text-lg font-bold">Project Status</h3>
  <p className="text-sm text-slate-500 dark:text-slate-400 mt-1">
    Automatically adapts when the user switches themes.
  </p>
</div>
COMPONENTS

Reusable Component Extraction

How to avoid class string duplication in React

Don't Overuse @apply

Do not create hundreds of custom CSS classes with @apply. That defeats the purpose of utility-first CSS and creates a bloated stylesheet.

Only use @apply for global HTML element resets.

Extract React Components

Wrap repeated markup in reusable components like <Button variant="primary" /> or <Card />.

This leads directly into modern component libraries like Shadcn UI!
BEST PRACTICES

Tailwind Developer Best Practices

Writing clean, maintainable utility markup

Order classes logically: Layout Spacing Typography Colors States
Install Tailwind CSS IntelliSense extension in VS Code / IDE
Use arbitrary values (w-[350px]) sparingly; stick to the scale
Use opacity modifiers like bg-blue-500/20 for sleek glows
Ensure high contrast in both Light Mode and Dark Mode
Use the cn() utility helper to merge conditional classes
SUMMARY

Tailwind CSS Mastery Checklist

You now have full control of modern utility styling

Utility-first philosophy: fast, scoped, zero CSS sprawl
Sizing and spacing scale (p-1 to p-5)
Flexbox and Grid responsive column layouts
Mobile-first responsive breakpoints (sm, md, lg, xl)
Micro-interactions with hover, focus, and transition
Seamless dark mode with dark: modifiers
Next step: Combine Tailwind with accessible Radix primitives in Shadcn UI!