Tailwind CSS Cheat Sheet
A complete reference of Tailwind CSS utility classes for both V3 and V4. Find classes for layout, typography, colors, spacing, responsive design, and more.
📚 Practice what you've learned with our Tailwind CSS Flashcards
Display
Controls the display type of an element
Syntax:
block | inline | inline-block | flex | grid | hiddenExamples:
block Makes element a block-level elementinline Makes element an inline elementinline-block Makes element inline-blockflex Makes element a flex containergrid Makes element a grid containerhidden Hides the elementNotes:
Essential for controlling element layout behavior
Position
Controls how an element is positioned
Syntax:
static | fixed | absolute | relative | stickyExamples:
static Default positioningfixed Fixed relative to viewportabsolute Absolute positioningrelative Relative positioningsticky Sticky positioningNotes:
Use with top, right, bottom, left utilities for precise placement
Top / Right / Bottom / Left
Controls placement of positioned elements
Syntax:
top-{size} | right-{size} | bottom-{size} | left-{size}Examples:
top-0 top: 0pxright-4 right: 1rembottom-auto bottom: autoleft-1/2 left: 50%inset-0 top: 0, right: 0, bottom: 0, left: 0Notes:
Works with positioned elements (relative, absolute, fixed, sticky)
Z-Index
Controls stack order of elements
Syntax:
z-{value}Examples:
z-0 z-index: 0z-10 z-index: 10z-20 z-index: 20z-50 z-index: 50z-auto z-index: autoNotes:
Higher values appear on top of lower values
Flex Direction
Controls direction of flex items
Syntax:
flex-row | flex-col | flex-row-reverse | flex-col-reverseExamples:
flex-row Horizontal direction (default)flex-col Vertical directionflex-row-reverse Horizontal reversedflex-col-reverse Vertical reversedNotes:
Must be used on a flex container
Flex Wrap
Controls whether flex items wrap
Syntax:
flex-wrap | flex-nowrap | flex-wrap-reverseExamples:
flex-wrap Allow items to wrapflex-nowrap Don't allow wrapping (default)flex-wrap-reverse Wrap in reverse orderNotes:
Determines if items stay on one line or can wrap to new lines
Justify Content
Controls alignment along main axis
Syntax:
justify-start | justify-center | justify-end | justify-between | justify-around | justify-evenlyExamples:
justify-start Align to start (default)justify-center Center itemsjustify-end Align to endjustify-between Space between itemsjustify-around Space around itemsjustify-evenly Even space between itemsNotes:
Controls horizontal alignment in flex-row, vertical in flex-col
Align Items
Controls alignment along cross axis
Syntax:
items-start | items-center | items-end | items-stretch | items-baselineExamples:
items-start Align to startitems-center Center itemsitems-end Align to enditems-stretch Stretch to fill (default)items-baseline Align to baselineNotes:
Controls vertical alignment in flex-row, horizontal in flex-col
Grid Template Columns/Rows
Defines grid track sizing
Syntax:
grid-cols-{n} | grid-rows-{n}Examples:
grid-cols-1 1 column gridgrid-cols-12 12 column gridgrid-cols-none No explicit columnsgrid-rows-3 3 row gridgrid-cols-[200px_1fr_100px] Custom column sizesNotes:
Must be used on a grid container
Column Span
Controls how many columns an element spans
Syntax:
col-span-{n} | col-start-{n} | col-end-{n}Examples:
col-span-2 Span 2 columnscol-span-full Span all columnscol-start-2 Start at column 2col-end-4 End at column 4col-auto Auto column placementNotes:
Used on grid items to control their column placement
Margin
Controls margin (outer spacing) of an element
Syntax:
m-{size} | mx-{size} | my-{size} | mt|mr|mb|ml-{size}Examples:
m-4 margin: 1rem (all sides)mx-auto margin-left: auto; margin-right: automy-8 margin-top: 2rem; margin-bottom: 2remmt-2 margin-top: 0.5remml-6 margin-left: 1.5rem-mx-4 Negative horizontal marginNotes:
Spacing scale: 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, etc.
Padding
Controls padding (inner spacing) of an element
Syntax:
p-{size} | px-{size} | py-{size} | pt|pr|pb|pl-{size}Examples:
p-4 padding: 1rem (all sides)px-6 padding-left: 1.5rem; padding-right: 1.5rempy-2 padding-top: 0.5rem; padding-bottom: 0.5rempt-8 padding-top: 2rempr-0 padding-right: 0Notes:
Uses same spacing scale as margin
Space Between
Controls space between child elements
Syntax:
space-x-{size} | space-y-{size}Examples:
space-x-4 Add horizontal space between childrenspace-y-2 Add vertical space between childrenspace-x-reverse Reverse horizontal spacing directionspace-y-reverse Reverse vertical spacing directionNotes:
Applies margin to all children except the first
Width
Controls the width of an element
Syntax:
w-{size} | w-{fraction} | w-{keyword}Examples:
w-32 width: 8remw-1/2 width: 50%w-full width: 100%w-screen width: 100vww-auto width: autow-fit width: fit-contentNotes:
Includes fixed sizes, fractions, and responsive keywords
Height
Controls the height of an element
Syntax:
h-{size} | h-{fraction} | h-{keyword}Examples:
h-64 height: 16remh-1/3 height: 33.333333%h-full height: 100%h-screen height: 100vhh-auto height: autoh-fit height: fit-contentNotes:
Similar sizing options as width
Min/Max Width
Controls minimum and maximum width constraints
Syntax:
min-w-{size} | max-w-{size}Examples:
min-w-0 min-width: 0pxmin-w-full min-width: 100%max-w-sm max-width: 24remmax-w-prose max-width: 65chmax-w-none max-width: noneNotes:
Useful for responsive design and content constraints
Font Family
Controls the font family of text
Syntax:
font-{family}Examples:
font-sans System sans-serif font stackfont-serif System serif font stackfont-mono System monospace font stackNotes:
Can be customized in tailwind.config.js
Font Size
Controls the size of text
Syntax:
text-{size}Examples:
text-xs font-size: 0.75rem; line-height: 1remtext-sm font-size: 0.875rem; line-height: 1.25remtext-base font-size: 1rem; line-height: 1.5remtext-lg font-size: 1.125rem; line-height: 1.75remtext-xl font-size: 1.25rem; line-height: 1.75remtext-6xl font-size: 3.75rem; line-height: 1Notes:
Also sets appropriate line-height for each size
Font Weight
Controls the weight (boldness) of text
Syntax:
font-{weight}Examples:
font-thin font-weight: 100font-light font-weight: 300font-normal font-weight: 400font-medium font-weight: 500font-semibold font-weight: 600font-bold font-weight: 700font-black font-weight: 900Notes:
Not all weights are available for every font
Text Align
Controls text alignment
Syntax:
text-{alignment}Examples:
text-left text-align: lefttext-center text-align: centertext-right text-align: righttext-justify text-align: justifytext-start text-align: starttext-end text-align: endNotes:
text-start and text-end respect text direction (RTL/LTR)
Line Height
Controls the line height of text
Syntax:
leading-{size}Examples:
leading-3 line-height: 0.75remleading-normal line-height: 1.5leading-relaxed line-height: 1.625leading-loose line-height: 2leading-none line-height: 1Notes:
Can use numeric values or named sizes
Text Color
Controls the color of text
Syntax:
text-{color}-{shade}Examples:
text-black color: #000000text-white color: #fffffftext-gray-500 color: #6b7280text-red-600 color: #dc2626text-blue-500 color: #3b82f6text-green-400 color: #4ade80Notes:
Color shades range from 50 (lightest) to 950 (darkest)
Background Color
Controls the background color of an element
Syntax:
bg-{color}-{shade}Examples:
bg-transparent background-color: transparentbg-white background-color: #ffffffbg-gray-100 background-color: #f3f4f6bg-blue-500 background-color: #3b82f6bg-red-50 background-color: #fef2f2Notes:
Same color palette as text colors
Border Color
Controls the color of borders
Syntax:
border-{color}-{shade}Examples:
border-transparent border-color: transparentborder-gray-300 border-color: #d1d5dbborder-blue-500 border-color: #3b82f6border-red-400 border-color: #f87171Notes:
Must be used with border width utility
Background Size
Controls the size of background images
Syntax:
bg-{size}Examples:
bg-auto background-size: autobg-cover background-size: coverbg-contain background-size: containNotes:
bg-cover is most commonly used for full coverage
Background Position
Controls the position of background images
Syntax:
bg-{position}Examples:
bg-center background-position: centerbg-top background-position: topbg-bottom background-position: bottombg-left background-position: leftbg-right background-position: rightbg-left-top background-position: left topNotes:
Can combine positions like bg-left-top
Background Repeat
Controls repetition of background images
Syntax:
bg-{repeat}Examples:
bg-repeat background-repeat: repeatbg-no-repeat background-repeat: no-repeatbg-repeat-x background-repeat: repeat-xbg-repeat-y background-repeat: repeat-yNotes:
bg-no-repeat is commonly used with bg-cover
Border Width
Controls border width
Syntax:
border-{width} | border-{side}-{width}Examples:
border border-width: 1px (all sides)border-2 border-width: 2px (all sides)border-t border-top-width: 1pxborder-r-4 border-right-width: 4pxborder-0 border-width: 0pxNotes:
Default border width is 1px when using 'border'
Border Style
Controls border style
Syntax:
border-{style}Examples:
border-solid border-style: solidborder-dashed border-style: dashedborder-dotted border-style: dottedborder-double border-style: doubleborder-none border-style: noneNotes:
border-solid is the default style
Border Radius
Controls border radius (rounded corners)
Syntax:
rounded-{size} | rounded-{corner}-{size}Examples:
rounded border-radius: 0.25remrounded-md border-radius: 0.375remrounded-lg border-radius: 0.5remrounded-full border-radius: 9999pxrounded-t-lg border-top-left-radius: 0.5rem; border-top-right-radius: 0.5remrounded-none border-radius: 0pxNotes:
rounded-full creates perfect circles for square elements
Box Shadow
Controls box shadow of an element
Syntax:
shadow-{size}Examples:
shadow-sm Small shadowshadow Default shadowshadow-md Medium shadowshadow-lg Large shadowshadow-xl Extra large shadowshadow-none No shadowshadow-inner Inner shadowNotes:
Shadows add depth and elevation to elements
Opacity
Controls opacity of an element
Syntax:
opacity-{value}Examples:
opacity-0 opacity: 0 (invisible)opacity-25 opacity: 0.25opacity-50 opacity: 0.5opacity-75 opacity: 0.75opacity-100 opacity: 1 (fully visible)Notes:
Opacity affects the entire element including children
Scale
Controls scaling transformation
Syntax:
scale-{value} | scale-x-{value} | scale-y-{value}Examples:
scale-50 transform: scale(0.5)scale-100 transform: scale(1) (default)scale-125 transform: scale(1.25)scale-x-150 transform: scaleX(1.5)scale-y-75 transform: scaleY(0.75)Notes:
Values are percentages: 100 = 100% = normal size
Rotate
Controls rotation transformation
Syntax:
rotate-{degrees}Examples:
rotate-0 transform: rotate(0deg)rotate-45 transform: rotate(45deg)rotate-90 transform: rotate(90deg)rotate-180 transform: rotate(180deg)-rotate-12 transform: rotate(-12deg)Notes:
Use negative values with dash prefix for counter-clockwise rotation
Translate
Controls translation (movement) transformation
Syntax:
translate-x-{value} | translate-y-{value}Examples:
translate-x-4 transform: translateX(1rem)translate-y-8 transform: translateY(2rem)-translate-x-2 transform: translateX(-0.5rem)translate-x-1/2 transform: translateX(50%)Notes:
Useful for positioning and animations
Transition Property
Controls which CSS properties transition
Syntax:
transition-{property}Examples:
transition Transition common propertiestransition-all Transition all propertiestransition-colors Transition color propertiestransition-opacity Transition opacitytransition-transform Transition transformstransition-none No transitionsNotes:
Use with duration and timing utilities for smooth animations
Transition Duration
Controls transition duration
Syntax:
duration-{time}Examples:
duration-75 transition-duration: 75msduration-150 transition-duration: 150msduration-300 transition-duration: 300msduration-500 transition-duration: 500msduration-1000 transition-duration: 1000msNotes:
300ms is a good default for most transitions
Transition Timing
Controls transition timing function
Syntax:
ease-{function}Examples:
ease-linear transition-timing-function: linearease-in transition-timing-function: ease-inease-out transition-timing-function: ease-outease-in-out transition-timing-function: ease-in-outNotes:
ease-in-out provides the most natural feeling transitions
Responsive Breakpoints
Apply utilities at specific screen sizes
Syntax:
sm: | md: | lg: | xl: | 2xl:Examples:
sm:text-lg Large text on small screens and upmd:flex Flex display on medium screens and uplg:w-1/2 Half width on large screens and upxl:px-8 Extra padding on extra large screens2xl:max-w-6xl Max width on 2xl screens and upNotes:
Breakpoints: sm(640px), md(768px), lg(1024px), xl(1280px), 2xl(1536px)
CSS Variables
Direct CSS variable support in V4
Syntax:
var(--{name})Examples:
text-[var(--primary)] Use CSS variable for text colorbg-[var(--surface)] Use CSS variable for backgroundborder-[var(--accent)] Use CSS variable for border colorNotes:
V4 has enhanced CSS variable integration
Enhanced Arbitrary Values
Improved arbitrary value support in V4
Syntax:
[value]Examples:
text-[#1da1f2] Custom hex colortext-[length:theme(fontSize.lg)] Theme value referencebg-[color:color-mix(in_srgb,theme(colors.blue.500)_50%,transparent)] CSS color-mix functionNotes:
V4 provides more powerful arbitrary value syntax
Container Queries
Native container query support in V4
Syntax:
@{size}:Examples:
@sm:text-lg Apply when container is small or larger@md:grid-cols-2 2 columns when container is medium@lg:p-8 More padding in large containersNotes:
Container queries allow responsive design based on container size, not viewport
Modern CSS Features
V4 includes modern CSS features out of the box
Syntax:
Various new utilitiesExamples:
bg-gradient-to-r CSS gradients with better syntaxbackdrop-blur-sm Backdrop filter supportsupports-grid:grid CSS @supports queriesmotion-reduce:animate-none Respect user motion preferencesNotes:
V4 embraces modern CSS features and better browser support
Hover States
Apply styles on hover
Syntax:
hover:{utility}Examples:
hover:bg-blue-500 Blue background on hoverhover:text-white White text on hoverhover:scale-105 Slightly scale up on hoverhover:shadow-lg Larger shadow on hoverNotes:
Essential for interactive elements like buttons and links
Focus States
Apply styles when element is focused
Syntax:
focus:{utility}Examples:
focus:outline-none Remove default focus outlinefocus:ring-2 Add focus ringfocus:ring-blue-500 Blue focus ring colorfocus:border-blue-500 Blue border on focusNotes:
Important for accessibility and keyboard navigation
Active States
Apply styles when element is being pressed/clicked
Syntax:
active:{utility}Examples:
active:bg-blue-700 Darker background when pressedactive:scale-95 Slightly scale down when pressedactive:transform Enable transforms for active stateNotes:
Provides immediate feedback when users interact with elements
🎨 What is Tailwind CSS?
Tailwind CSS is a utility-first CSS framework created by Adam Wathan in 2017. Unlike traditional CSS frameworks that provide pre-designed components (like Bootstrap), Tailwind provides low-level utility classes that let you build custom designs directly in your HTML. With over 3 million weekly downloads on npm, Tailwind has revolutionized how developers approach CSS, offering unprecedented flexibility and maintainability while dramatically speeding up development.
🚀 Core Philosophy
- ✓ Utility-first: Small, single-purpose classes for maximum flexibility
- ✓ Component-agnostic: Build any design without fighting the framework
- ✓ Responsive by default: Mobile-first responsive design built-in
- ✓ Highly customizable: Configure every aspect via config files
- ✓ Developer experience: Autocomplete, IntelliSense, and great tooling
- ✓ Production-ready: Automatic purging removes unused CSS
💡 Why Choose Tailwind?
- • Faster development: Style directly in HTML without switching files
- • Consistent design: Predefined scale ensures visual harmony
- • Smaller CSS bundles: Only ship the CSS you actually use
- • Easy maintenance: No more hunting through CSS files
- • Team collaboration: Shared design system through utilities
- • Framework agnostic: Works with React, Vue, Angular, vanilla HTML
🎯 Utility-First Approach
Traditional CSS
.btn-primary { background: blue; color: white; padding: 12px 24px; border-radius: 6px; } <button class="btn-primary">Click me</button>Requires writing custom CSS classes
Tailwind CSS
<button class="bg-blue-500 text-white px-6 py-3 rounded-lg hover:bg-blue-600">Click me</button>Compose styles using utility classes
🏗️ Tailwind Architecture
🎨 Design Tokens
Colors, spacing, typography scales defined in config
theme: { colors: {...} }🔧 Utilities
Single-purpose classes generated from tokens
text-blue-500📱 Responsive
Breakpoint prefixes for responsive design
md:text-lg🌙 Variants
State and context modifiers
hover:bg-blue-600🌟 Key Features
Responsive Design
- • Mobile-first breakpoints
- •
sm:md:lg:xl:prefixes - • Container queries (V4)
- • Arbitrary breakpoints
Dark Mode
- • Built-in dark mode support
- •
dark:prefix for variants - • System preference detection
- • Manual toggle support
State Variants
- •
hover:focus:active: - •
first:last:odd:even: - •
group-hover:peer-focus: - • Custom variant creation
📦 Tailwind Ecosystem
Core Tools
- • Tailwind CLI: Standalone build tool
- • PostCSS Plugin: Integration with build systems
- • JIT Compiler: Just-in-time CSS generation
- • Play CDN: Quick prototyping without build step
- • Tailwind UI: Official component library
Editor Support
- • IntelliSense: VS Code extension with autocomplete
- • Class sorting: Prettier plugin for consistent order
- • Syntax highlighting: Better readability
- • Linting: Catch errors and inconsistencies
- • Fold/unfold: Manage long class lists
🚀 Getting Started with Tailwind
1. Installation
npm install -D tailwindcss •
Initialize config: npx tailwindcss init
2. Configuration
Set up content paths • Configure theme customizations • Add plugins and variants as needed
3. Build Process
Include Tailwind directives • Set up build command • Configure purging for production
4. Start Building
Learn utility classes • Practice with components • Explore responsive design patterns
⚖️ Tailwind vs. Other Frameworks
Tailwind Advantages
- • No opinionated design decisions
- • Tiny production CSS bundles
- • Rapid prototyping and iteration
- • Consistent design systems
- • No naming conventions to learn
- • Framework/library agnostic
Popular Alternatives
- • Bootstrap: Component-based, faster for prototypes
- • Bulma: Modern CSS flexbox framework
- • Chakra UI: React component library with design system
- • Material-UI: Google's Material Design implementation
- • CSS-in-JS: Runtime styling solutions (Styled Components)
🏗️ Tailwind Best Practices
Component Extraction
- • Extract common patterns into components
- • Use @apply for repeated utility combinations
- • Create design system components
- • Balance utility-first with component abstraction
Development Workflow
- • Start with utilities, extract components later
- • Use editor extensions for productivity
- • Configure purging for optimal bundle size
- • Test across breakpoints and themes
Tailwind Philosophy: "It's easier to achieve a good design when you're limited to a set of constraints than when you can do literally anything." Embrace the utility-first approach and watch your CSS become more maintainable and your designs more consistent! 🎨
Pro Tailwind Tips
Related Resources
Essential Patterns
flex items-center justify-center- Perfect centeringgrid grid-cols-1 md:grid-cols-2- Responsive gridmax-w-4xl mx-auto- Centered containerspace-y-4- Consistent vertical spacingtransition-all duration-300- Smooth animationsfocus:ring-2 focus:ring-blue-500- Accessible focus
Best Practices
- Use semantic color names (primary, secondary) in config
- Leverage responsive prefixes:
sm:,md:,lg: - Group related utilities together for readability
- Use arbitrary values sparingly:
[14px] - Create component classes for repeated patterns
- Test dark mode with
dark:variants
V3 vs V4 Key Differences
- • V4: Enhanced CSS variable support
- • V4: Native container queries (@sm:, @md:)
- • V4: Better arbitrary value syntax
- • V4: Modern CSS features built-in
- • V4: Smaller bundle sizes
Common Component Pattern
/* Button Component */ class="px-4 py-2 bg-blue-500 text-white font-medium rounded-lg shadow-sm hover:bg-blue-600 focus:ring-2 focus:ring-blue-500 transition-colors duration-200"Version Compatibility
| Feature | Tailwind V3 | Tailwind V4 |
|---|---|---|
| Core Utilities | ||
| Container Queries | ||
| Enhanced CSS Variables | ||
| Modern CSS Features |