Time to learn Tailwind CSS - the most popular CSS framework in 2024.
Tailwind is a utility-first CSS framework. Instead of writing CSS manually, you use ready-made classes.
1.button {
2 background-color: #dc2626;
3 color: white;
4 padding: 12px 24px;
5 border-radius: 8px;
6 font-weight: 600;
7}1<button class="button">Click me</button>1<button class="bg-red-600 text-white px-6 py-3 rounded-lg font-semibold">
2 Click me
3</button>Everything in HTML classes! You don't write CSS - you use ready-made classes.
✅ Speed - no switching between HTML and CSS ✅ Consistency - one system of colors, spacing ✅ Responsiveness - easy breakpoints (sm:, md:, lg:) ✅ No conflicts - no accidentally overriding styles ✅ Tree-shaking - only used classes in the final CSS ✅ Used by - GitHub, Shopify, Netflix
Background:
bg-red-500 - red backgroundbg-blue-600 - blue backgroundbg-black - black backgroundbg-white - white backgroundText:
text-red-500 - red texttext-blue-600 - blue texttext-gray-900 - dark gray textColors have shades from 50 (lightest) to 950 (darkest).
Padding (inner spacing):
p-4 - padding 16px on all sidespx-4 - padding 16px left and rightpy-4 - padding 16px top and bottompt-4 - padding-top 16pxpr-4 - padding-right 16pxMargin (outer spacing):
m-4 - margin 16pxmx-auto - centering (margin left/right auto)mt-8 - margin-top 32pxScale: 0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 40...
p-1 = 4pxp-2 = 8pxp-4 = 16pxp-8 = 32pxSize:
text-xs - extra smalltext-sm - smalltext-base - normal (16px)text-lg - largetext-xl - extra largetext-2xl, text-3xl, text-4xl - largerWeight:
font-light - lightfont-normal - normalfont-medium - mediumfont-semibold - semi-boldfont-bold - boldAlignment:
text-left - lefttext-center - centertext-right - rightDisplay:
block - display: blockinline - display: inlineflex - display: flexgrid - display: gridhidden - display: noneFlexbox:
flex - activates flexboxflex-row - horizontal direction (default)flex-col - vertical directionitems-center - vertical centeringjustify-center - horizontal centeringgap-4 - gap between elementsWidth:
w-full - width: 100%w-1/2 - width: 50%w-screen - width: 100vwmax-w-md - max-width: 448pxmax-w-4xl - max-width: 896pxHeight:
h-screen - height: 100vh (full screen)min-h-screen - min-height: 100vhBorder:
border - border 1pxborder-2 - border 2pxborder-red-500 - red borderRadius (rounding):
rounded - border-radius 4pxrounded-lg - larger roundingrounded-full - full circle (50%)Tailwind has built-in breakpoints:
sm: - 640px (portrait tablet)md: - 768px (landscape tablet)lg: - 1024px (laptop)xl: - 1280px (desktop)Example:
1<div class="text-sm md:text-base lg:text-lg">
2 Responsive text
3</div>text-sm (14px)text-base (16px)text-lg (18px)Mobile-first: you write for mobile, then add breakpoints for larger screens.
1<button class="
2 bg-red-600
3 hover:bg-red-700
4 text-white
5 font-bold
6 py-3
7 px-6
8 rounded-lg
9 transition-colors
10 duration-200
11">
12 Join the crew!
13</button>What's happening:
bg-red-600 - red backgroundhover:bg-red-700 - darker on hovertext-white - white textfont-bold - boldpy-3 - padding top/bottompx-6 - padding left/rightrounded-lg - rounded cornerstransition-colors - smooth color transitionduration-200 - 200ms transitionInstead of memorizing all classes, ask AI!
Prompt:
1Create a pirate hero section in Tailwind with a black background, red heading and gold buttonAI will generate the entire code with appropriate Tailwind classes!
In Next.js, Tailwind is already configured (if you chose "Yes" during setup).
Configuration files:
tailwind.config.ts - configuration (colors, fonts)app/globals.css - Tailwind directivesIn
globals.css you'll see:1@tailwind base;
2@tailwind components;
3@tailwind utilities;This imports all Tailwind classes.
Tailwind supports dark mode:
1<div class="bg-white dark:bg-gray-900 text-black dark:text-white">
2 Auto dark mode!
3</div>✅ Tailwind CSS - utility-first framework ✅ Classes in HTML - no manual CSS writing ✅ bg-, text-, p-, m- - basic classes ✅ sm:, md:, lg: - responsive breakpoints ✅ hover:, focus: - interactive states ✅ AI helps - ask for specific styles
In the next exercise we'll create a landing page for "Kraken's Call"!
See you there! 🚀