Tailwind replaces writing CSS files with composing utility classes directly in HTML. This lesson covers setup, the utility-first philosophy, and building layouts with Flexbox and Grid.
Tailwind replaces writing CSS files with composing utility classes directly in HTML. This lesson covers setup, the utility-first philosophy, and building layouts with Flexbox and Grid.
Traditional CSS: you write .card { padding: 16px; background: white; border-radius: 8px; } in a CSS file, then apply class="card". With Tailwind: class="p-4 bg-white rounded-lg". No separate CSS file. No naming classes.
The tradeoff: HTML gets more verbose, but you never context-switch to a CSS file and you never worry about naming. Most developers prefer it after one project.
npm create vite@latest my-app -- --template vanilla cd my-app && npm install npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p
/** @type {import('tailwindcss').Config} */
export default { content: ['./index.html', './src/**/*.{js,ts,jsx,tsx,vue,svelte}'], theme: { extend: {} }, plugins: []
} @tailwind base; @tailwind components; @tailwind utilities;
SpacingHeading
Body text
Blue backgroundWarm boxSized box
Left (grows)Right (fixed)Title
Content
MainSidebarCard
p-4 is 16px, p-6 is 24px, p-8 is 32px. After a day of using it, you internalize the scale and stop thinking in pixels.Before moving on, make sure you can answer these without looking: