Skip to main content
Simple summary of the most commonly used Tailwind elements for easy reference.
Official documentation: tailwindcss.com/docs

Visual Styling (Text & Colors)

Syntax

  • text-{color}-{shade}: Changes font color
  • text-{size}: Size (xs, sm, base, lg, xl, 2xl…)
  • text-{align}: Direction (left, center, right, justify)
  • bg-{color}-{shade}: Background color
  • hover:: Effect on mouse hover

Example

<button class="bg-blue-600 text-white font-bold py-2 px-6 rounded
               hover:bg-blue-400 hover:text-black transition-all">
  Hover me
</button>

Color Reference

  • gray, slate, zinc, neutral, stone
  • red, orange, amber, yellow, lime
  • green, emerald, teal, cyan, sky
  • blue, indigo, violet, purple, fuchsia
  • pink, rose

Spacing & Dimensions

  • m-{size}: Margin all sides
  • mt-, mr-, mb-, ml-: Top, Right, Bottom, Left
  • mx-{size}: Horizontal (left + right)
  • my-{size}: Vertical (top + bottom)
<div class="m-4">Margin 1rem all sides</div>
<div class="mx-auto">Centered horizontally</div>
  • p-{size}: Padding all sides
  • pt-, pr-, pb-, pl-: Top, Right, Bottom, Left
  • px-{size}: Horizontal (left + right)
  • py-{size}: Vertical (top + bottom)
<div class="p-4">Padding 1rem all sides</div>
<button class="px-6 py-2">Button with padding</button>

Spacing Scale

ClassValuePixels
000px
10.25rem4px
20.5rem8px
41rem16px
61.5rem24px
82rem32px
123rem48px
164rem64px

Borders & Rounding

<div class="border border-gray-300">Default border</div>
<div class="border-2 border-blue-500">Thick blue border</div>
<div class="border-t border-b">Top and bottom only</div>

Layout (Flex & Grid)

Basic Flex

<div class="flex gap-4">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

Alignment

  • justify-start, justify-center, justify-end, justify-between
  • items-start, items-center, items-end
  • flex-col: Stack vertically
  • flex-row: Stack horizontally (default)
<div class="flex justify-between items-center">
  <div>Left</div>
  <div>Right</div>
</div>
Use gap-{size} instead of margins between flex/grid items for cleaner code.

Responsive Design (Breakpoints)

Tailwind uses a mobile-first approach. Base classes apply to all screen sizes, then override with breakpoint prefixes.
PrefixMin WidthDevice
(Base)0pxMobile (Default)
sm:640pxMobile Landscape
md:768pxTablets / iPads
lg:1024pxLaptops
xl:1280pxDesktops
2xl:1536pxLarge Screens

Responsive Example

<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
  <!-- 1 column on mobile, 2 on tablet, 4 on desktop -->
</div>

<h1 class="text-2xl md:text-4xl lg:text-6xl">
  <!-- Larger text on bigger screens -->
</h1>

<div class="hidden md:block">
  <!-- Hidden on mobile, visible on tablet+ -->
</div>
Breakpoints stack: md:text-xl applies to medium screens and larger (unless overridden by lg:, xl:, etc.).

Common Patterns

<div class="max-w-7xl mx-auto px-4">
  <!-- Content -->
</div>
<div class="bg-white rounded-lg shadow-lg p-6 border border-gray-200">
  <h2 class="text-xl font-bold mb-4">Card Title</h2>
  <p class="text-gray-600">Card content goes here...</p>
</div>
<!-- Primary -->
<button class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
  Primary
</button>

<!-- Secondary -->
<button class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-4 rounded">
  Secondary
</button>

<!-- Outline -->
<button class="border-2 border-blue-600 text-blue-600 hover:bg-blue-600 hover:text-white font-bold py-2 px-4 rounded">
  Outline
</button>
<input 
  type="text" 
  placeholder="Enter your name..."
  class="w-full px-4 py-2 border border-gray-300 rounded-lg 
         focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
/>

Utility Classes Reference

ClassDescription
font-boldFont weight bold
italicItalic text
uppercaseUPPERCASE TEXT
lowercaselowercase text
capitalizeCapitalize First Letter
underlineUnderlined text
line-throughStrikethrough

Arbitrary Values

When you need a specific value not in the default scale, use square brackets:
<div class="w-[137px] h-[23px] bg-[#1da1f2] text-[15px]">
  Custom values
</div>
Use arbitrary values sparingly. Stick to the default scale when possible for consistency.

Build docs developers (and LLMs) love