Tailwind CSS Basics Cheatsheet
Quick reference for all Tailwind CSS utility classes covered in Lecture 6.
Tailwind CSS 4 CDN Setup
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>My Page</title>
7 <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
8</head>
9<body class="bg-slate-950 text-gray-100">
10
11</body>
12</html>
One script tag. No npm. No config. That's it.
Spacing Scale (4px Base)
Every spacing value is a multiple of 4px: number × 4 = pixels.
Spacing Directions
Same pattern for margin: m-*, mx-*, my-*, mt-*, mb-*, ml-*, mr-*
Pro Tip: Quick math — p-6 = 6 × 4 = 24px = 1.5rem. Works for every spacing utility.
Layout Utilities
Flexbox
1
2<div class="flex justify-between items-center">...</div>
3
4
5<div class="flex flex-col gap-4">...</div>
6
7
8<div class="flex items-center justify-center">...</div>
Grid
1
2<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">...</div>
Sizing
Container Pattern
1
2<div class="max-w-7xl mx-auto px-6">...</div>
Typography
1<h1 class="text-5xl font-bold tracking-tight leading-tight">Heading</h1>
2<p class="text-lg text-gray-400 leading-relaxed">Body text</p>
3<span class="text-sm uppercase tracking-widest">Label</span>
Font Sizes
Font Weight
Other Typography
Color System
Every color has shades from 50 (lightest) to 950 (darkest).
150 → 100 → 200 → 300 → 400 → 500 → 600 → 700 → 800 → 900 → 950
2lightest base darkest
Common Colors Used in This Lecture
Opacity Shorthand
1
2<div class="bg-black/60">...</div>
3
4
5<div class="border-amber-500/30">...</div>
The /number syntax sets opacity (0-100). Replaces rgba() from traditional CSS.
Borders, Rounded Corners & Shadows
1<div class="border border-slate-700 rounded-xl shadow-lg">...</div>
State Modifiers
Tailwind uses modifier:class syntax to style interactive states.
1
2<div class="hover:bg-slate-800 hover:-translate-y-2 transition duration-300">
3
4
5<input class="focus:ring-2 focus:ring-amber-500 focus:outline-none">
6
7
8<button class="active:scale-95">
Syntax: modifier:property-value — colon separates modifier from class.
Common mistake: Using a dash instead of a colon: hover-bg-blue-500 (wrong) → hover:bg-blue-500 (correct)
Transitions & Transforms
1
2<div class="hover:-translate-y-2 hover:shadow-xl transition duration-300">
3
4
5<img class="hover:scale-105 transition-transform duration-300">
Transitions
Transforms
Responsive Prefixes
Base classes = mobile. Prefixed classes ADD rules for larger screens.
1
2<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
Breakpoints
Common Responsive Patterns
1
2<h1 class="text-3xl md:text-5xl lg:text-7xl">
3
4
5<ul class="hidden md:flex">
6
7
8<form class="flex flex-col sm:flex-row gap-4">
9
10
11<section class="py-12 md:py-20">
Key Rule: Same mobile-first from Lecture 5 — base = mobile, prefixes ADD for larger. No max-width equivalent — always min-width.
Positioning & Overlays
1
2<div class="relative">
3 <img class="absolute inset-0 w-full h-full object-cover">
4 <div class="absolute inset-0 bg-black/60"></div>
5 <div class="relative z-10">Content above overlay</div>
6</div>
Common Mistakes to Avoid
1. Missing Color Shade
1
2<div class="bg-blue text-gray">
3
4
5<div class="bg-blue-500 text-gray-400">
2. Wrong Modifier Syntax
1
2<button class="hover-bg-blue-700">
3
4
5<button class="hover:bg-blue-700">
3. Missing Transition with Hover Transform
1
2<div class="hover:-translate-y-2">
3
4
5<div class="hover:-translate-y-2 transition duration-300">
4. Missing CDN Script Tag
1
2<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
VS Code + Tailwind IntelliSense
Extension Setup
Install: Tailwind CSS IntelliSense by Tailwind Labs
Shortcuts
Quick Reference Table
What's Next?
In Lecture 7: Advanced Tailwind & Customization, you'll learn:
- Custom theme configuration (
@theme directive) - Your own brand colors and spacing scale
- Component extraction with
@apply - Building a complete Restaurant Digital Menu
- Moving from CDN to production build tools
> "Today you used Tailwind's defaults. Next, you make Tailwind YOUR tool — custom colors, custom spacing, reusable components."
Keep this cheatsheet handy while working on your assignment!