Get ready for your next interview with our comprehensive question library
The utility-first approach means using small, single-purpose classes that apply specific styles rather than semantic class names. Each utility class does one thing well.
Advantages:
Installation methods:
<link href="https://cdn.tailwindcss.com" rel="stylesheet">
npm install tailwindcss
tailwindcss
binaryThe PostCSS plugin approach is recommended for production as it allows customization and purging.
The tailwind.config.js
file is the main configuration file that allows you to:
Tailwind utilities follow a predictable naming pattern based on CSS properties:
Common examples:
p-4
(padding: 1rem), px-2
(horizontal padding: 0.5rem)m-8
(margin: 2rem), mt-4
(margin-top: 1rem)bg-blue-500
(background), text-red-600
(color)flex
, block
, hidden
, inline-block
w-64
(width: 16rem), h-screen
(height: 100vh)The pattern is usually: [property]-[value]
or [property][direction]-[value]
Tailwind uses a consistent spacing scale based on 0.25rem
(4px) increments:
0
= 0px1
= 0.25rem (4px)2
= 0.5rem (8px)4
= 1rem (16px)8
= 2rem (32px)16
= 4rem (64px)Examples:
p-4
= padding: 1remm-8
= margin: 2remspace-x-4
= gap of 1rem between child elements horizontallyThis scale provides consistent spacing throughout your design.
Tailwind provides comprehensive flexbox utilities:
Basic flex container:
<div class="flex items-center justify-between">
<div>Left</div>
<div>Right</div>
</div>
Common flexbox utilities:
flex
- display: flexflex-col
- flex-direction: columnitems-center
- align-items: centerjustify-between
- justify-content: space-betweenflex-1
- flex: 1 1 0%flex-shrink-0
- flex-shrink: 0Tailwind provides position utilities with corresponding placement utilities:
Position types:
relative
- position: relativeabsolute
- position: absolutefixed
- position: fixedsticky
- position: stickyPlacement utilities:
top-0
, right-0
, bottom-0
, left-0
inset-0
- top, right, bottom, left: 0inset-x-4
- left and right: 1reminset-y-2
- top and bottom: 0.5remExample:
<div class="relative">
<div class="absolute top-2 right-2">Positioned element</div>
</div>
Tailwind uses a mobile-first responsive approach with breakpoint prefixes:
Default breakpoints:
sm:
- 640px and upmd:
- 768px and uplg:
- 1024px and upxl:
- 1280px and up2xl:
- 1536px and upExample:
<div class="text-sm md:text-base lg:text-lg xl:text-xl">
Responsive text
</div>
Styles apply from the specified breakpoint upward unless overridden.
Tailwind uses a numbered color scale from 50 (lightest) to 950 (darkest):
Color scale:
50
- Very light tint100
, 200
, 300
- Light shades400
, 500
, 600
- Medium shades (500 is the base)700
, 800
, 900
- Dark shades950
- Very dark shadeUsage examples:
bg-blue-500
- Blue background (medium blue)text-gray-700
- Dark gray textborder-red-200
- Light red borderThis system provides consistent color relationships across your design.
Opacity utilities control the transparency of elements using a 0-100 scale:
Examples:
opacity-0
- Fully transparent (0%)opacity-25
- 25% opacityopacity-50
- 50% opacityopacity-75
- 75% opacityopacity-100
- Fully opaque (100%)Color opacity:
You can also modify opacity of background colors, text colors, etc.:
bg-blue-500/50
- Blue background with 50% opacitytext-red-600/75
- Red text with 75% opacityThis is useful for overlays, disabled states, and creating depth in designs.
Upgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumAccess all premium content - interview questions, and other learning resources
We regularly update our features and content, to ensure you get the most relevant and updated premium content.
1000 monthly credits
Cancel anytime