p-8
mean?p
= padding on all sides8
= spacing unit from Tailwindβs scaleπ’ p-8
= padding: 2rem;
β Since 1rem = 16px
, thatβs 32px padding on all sides.
p
Class | Meaning |
---|---|
p-8 | padding on all sides |
pt-8 | padding-top |
pb-8 | padding-bottom |
pl-8 | padding-left |
pr-8 | padding-right |
px-8 | padding left + right |
py-8 | padding top + bottom |
p-8
.
text-3xl
mean?text
= text size3xl
= size level (larger than base text)π€ text-3xl
sets the font size to 1.875rem
(about 30px).
This is text-3xl
size text β big and bold!
Class | Font Size (rem) | Font Size (px) | Description |
---|---|---|---|
text-xs | 0.75rem | 12px | Extra small |
text-sm | 0.875rem | 14px | Small |
text-base | 1rem | 16px | Base (normal) size |
text-lg | 1.125rem | 18px | Large |
text-xl | 1.25rem | 20px | Extra large |
text-2xl | 1.5rem | 24px | 2Γ Extra large |
text-3xl | 1.875rem | 30px | 3Γ Extra large |
text-4xl | 2.25rem | 36px | 4Γ Extra large |
text-5xl | 3rem | 48px | 5Γ Extra large |
text-6xl | 3.75rem | 60px | 6Γ Extra large |
text-7xl | 4.5rem | 72px | 7Γ Extra large |
text-8xl | 6rem | 96px | 8Γ Extra large |
text-9xl | 8rem | 128px | 9Γ Extra large |
bg-gray-100
mean?bg
= backgroundgray
= color name100
= shade level (100 = very light)Tailwind uses a color scale ranging from 50
(lightest) to 950
(darkest). Thatβs 19 levels per color.
Shade | Example Color | Description |
---|---|---|
gray-50 | Very Light | |
gray-100 | Light | |
gray-400 | Medium | |
gray-800 | Dark | |
gray-950 | Very Dark |
border-t-2
mean?border
= apply a bordert
= top side2
= border thickness (2px)So border-t-2
means: add a 2px border only to the top of the element.
border-t-2
.
Class | Thickness | Description |
---|---|---|
border | 1px | Default (1px on all sides) |
border-t-2 | 2px | Top border only |
border-b-4 | 4px | Bottom border only |
border-l-8 | 8px | Left border only |
rounded
mean?rounded
adds rounded corners to an element.border-radius
in CSS.Class | Effect |
---|---|
rounded | Small border radius |
rounded-md | Medium border radius |
rounded-lg | Large border radius |
rounded-full | Circle/fully rounded (useful for avatars) |
font
mean?font-*
classes to change font weight.Here are some examples:
font-thin (100)
font-normal (400)
font-semibold (600)
font-bold (700)
font-black (900)
Class | Weight | Description |
---|---|---|
font-thin | 100 | Very light |
font-normal | 400 | Regular |
font-semibold | 600 | Semi-bold |
font-bold | 700 | Bold |
font-black | 900 | Extra bold |
x
and y
mean in Tailwind?x
= horizontal (left and right)y
= vertical (top and bottom)m
and padding p
like: mx-4
, py-6
Class | Effect |
---|---|
px-8 | Padding left & right (32px) |
py-4 | Padding top & bottom (16px) |
mx-6 | Margin left & right (24px) |
my-2 | Margin top & bottom (8px) |
position
do in Tailwind CSS?Tailwind provides utility classes to control how elements are positioned on the screen.
static
β default (no special positioning)relative
β positioned relative to its normal placeabsolute
β positioned relative to the nearest positioned ancestorfixed
β positioned relative to the browser windowsticky
β scrolls normally until it reaches a threshold, then sticksThis box is relative
(positioned normally).
Scroll me to see sticky effect
Class | Meaning | Description |
---|---|---|
static | Default | Element stays in normal flow (no positioning) |
relative | Relative | Offset from normal position using top/right/bottom/left |
absolute | Absolute | Placed inside the nearest ancestor with relative/absolute/fixed |
fixed | Fixed | Stays in place even during scroll (relative to viewport) |
sticky | Sticky | Scrolls until it reaches a scroll position, then sticks |
block
, inline
, and inline-block
in Tailwind?These utility classes control how elements flow and wrap in the layout. Each has different behavior.
πΉ block
(takes full width)
πΈ inline
(sits next to each other)
πΈ inline-block
(sits inline but allows box sizing)
Class | CSS | Behavior |
---|---|---|
block | display: block; | Takes full width, stacks vertically |
inline | display: inline; | Flows inline, ignores width/height |
inline-block | display: inline-block; | Flows inline, but respects width/height |
flex
mean in Tailwind CSS?Tailwind uses the flex
utility to apply flexbox layout to elements. Flexbox helps align, distribute, and arrange elements responsively.
flex
β sets the element to display: flexflex-row
β default direction (horizontal)flex-col
β vertical stackingπΉ flex
creates a row by default.
πΈ flex-col
stacks items vertically.
Class | Effect | CSS Equivalent |
---|---|---|
block | Block-level box | display: block; |
inline-block | Inline + block | display: inline-block; |
flex | Flexbox container | display: flex; |
inline-flex | Inline flex container | display: inline-flex; |
grid | Grid layout | display: grid; |
hidden | Hide element | display: none; |
Class | Direction | CSS |
---|---|---|
flex-row | Horizontal | flex-direction: row; |
flex-col | Vertical | flex-direction: column; |
flex-row-reverse | Row reversed | flex-direction: row-reverse; |
flex-col-reverse | Column reversed | flex-direction: column-reverse; |
grid
in Tailwind CSS?
Tailwindβs grid
utility enables you to create powerful and responsive layouts using CSS Grid.
It's great for laying out boxes, cards, galleries, and more.
Above uses grid grid-cols-3
β creates 3 equal-width columns.
Class | Effect | CSS Equivalent |
---|---|---|
grid | Enables grid display | display: grid; |
grid-cols-2 | 2 equal columns | grid-template-columns: repeat(2, 1fr); |
grid-cols-4 | 4 equal columns | grid-template-columns: repeat(4, 1fr); |
gap-4 | Adds spacing between items | gap: 1rem; |
col-span-2 | Item spans 2 columns | grid-column: span 2 / span 2; |
leading-relaxed
mean in Tailwind CSS?
The class leading-relaxed
sets the line height (the vertical space between lines of text) to make content easier to read.
leading-relaxed
β line-height: 1.625;
So, if your text has a font size of 16px
, the line height will be:
16px Γ 1.625 = 26px
leading-relaxed
. Notice how the lines are comfortably spaced, which improves readability for longer content such as articles, documentation, or educational materials.
leading-*
values in Tailwind:Class | Line Height | Description |
---|---|---|
leading-none | 1 | No spacing between lines |
leading-tight | 1.25 | Tighter line spacing |
leading-snug | 1.375 | Slightly tight |
leading-normal | 1.5 | Normal spacing |
leading-relaxed | 1.625 | Relaxed and readable β |
leading-loose | 2 | Very loose spacing |
leading-relaxed
?shadow
in Tailwind CSS?Tailwind provides utility classes to easily apply different levels of box shadow to your elements. Shadows can enhance the appearance by adding depth and focus.
Class | Description |
---|---|
shadow-sm | Small shadow |
shadow | Default medium shadow |
shadow-md | Medium shadow |
shadow-lg | Large shadow |
shadow-xl | Extra large shadow |
shadow-2xl | Huge shadow |
shadow-inner | Inner shadow |
shadow-none | Removes shadow |
This button uses shadow-lg
to give it a large shadow:
shadow-lg
to shadow-sm
or shadow-2xl
to see the effect.shadow-inner
inside a light-colored box for a soft inset look.hover
, focus
, and transform
Tailwind allows you to add interactive effects using pseudo-classes like hover
and focus
, and also animate objects using transform
.
hover:
β When mouse hovers over an element
Use hover:
before any utility to apply styles on hover.
hover:bg-blue-700
means background turns dark blue when you hover.
focus:
β When input is clicked or selectedfocus:ring-2
and focus:ring-blue-500
add a blue border ring when focused.
transform
β Move, scale, or rotate elements
The transform
class enables transformations like:
hover:scale-110
β make it 110% sizehover:rotate-3
β rotate 3 degreeshover:translate-x-2
β move rightClass | Effect |
---|---|
scale-110 | Scales to 110% |
rotate-6 | Rotates 6Β° |
translate-x-2 | Moves 0.5rem to right |
-translate-y-1 | Moves 0.25rem upward |
transition
and duration-300
to smooth effectshover:
+ transform
for animated buttons, cards, imagesTailwind makes responsive design super easy using mobile-first breakpoints. You can apply styles that change based on the deviceβs screen width.
screen-size:class
For example: md:text-xl
means "apply text-xl when the screen is medium or larger".
Prefix | Min Width | Device Type |
---|---|---|
sm | 640px | Small devices (e.g., phones) |
md | 768px | Medium devices (e.g., tablets) |
lg | 1024px | Large devices (e.g., laptops) |
xl | 1280px | Extra large (e.g., desktops) |
2xl | 1536px | Big screens (e.g., TVs, monitors) |
This heading will be small on phones, but grow on bigger screens:
px-4
, text-center
, hidden
, etc.Tailwind CSS includes built-in utility classes to control the visibility of elements β without writing custom CSS.
hidden
The hidden
class completely removes the element from the layout by applying display: none;
.
hidden
!
invisible
vs. visible
Use invisible
to hide an element but still keep its space in the layout. Use visible
to reverse it.
invisible
= visibility: hidden;
visible
= visibility: visible;
You can use responsive prefixes like md:hidden
or lg:visible
to show/hide elements on specific screen sizes.
md:hidden
).
Class | Effect |
---|---|
hidden |
Removes from layout (display: none; ) |
invisible |
Hidden but keeps space (visibility: hidden; ) |
visible |
Makes invisible elements visible again |
π‘ Tip: Combine with responsive prefixes like md:hidden
, sm:invisible
, or lg:visible
to control visibility across screen sizes.
md
in Tailwind CSSmd
as a Breakpoint (for responsiveness)When you see md:
at the beginning of a class, it means:
"Apply this style starting from medium screens (β₯768px width)."
<div class="bg-red-500 md:bg-green-500">
bg-red-500
bg-green-500
Prefix | Min Width | Device Type |
---|---|---|
sm | 640px | Small phones |
md | 768px | Tablets / Small laptops |
lg | 1024px | Laptops / Desktops |
xl | 1280px | Large desktops |
2xl | 1536px | Very large screens |
md
as a Size Value (like in max-w-md
)In utility classes that control size (e.g., width, max-width, spacing), md
refers to a predefined size value.
<div class="max-w-md">
This sets:
max-width: 28rem; /* which is 448px */
Class | Value |
---|---|
max-w-sm | 24rem (384px) |
max-w-md | 28rem (448px) |
max-w-lg | 32rem (512px) |
max-w-xl | 36rem (576px) |
Use Case | Meaning |
---|---|
md: (prefix) | Breakpoint β₯768px |
max-w-md | Size = 28rem (448px) |
space-y-6
in Tailwind CSS
space-y-6
?
The class space-y-6
is used to add vertical spacing between direct child elements of a parent container.
It adds 1.5rem
(or 24px) of space between each element stacked vertically.
It's a cleaner alternative to adding mb-6
to every child manually.
> * + * {
margin-top: 1.5rem; /* 24px */
}
The following layout stacks three boxes vertically with 24px spacing between them using space-y-6
:
You can adjust spacing with different values like space-y-1
, space-y-2
, etc.
Class | Spacing (rem) | Pixels |
---|---|---|
space-y-1 | 0.25rem | 4px |
space-y-2 | 0.5rem | 8px |
space-y-4 | 1rem | 16px |
space-y-6 | 1.5rem | 24px |
space-y-8 | 2rem | 32px |
space-y-10 | 2.5rem | 40px |
You can also use space-x-6
to add horizontal spacing between inline elements, like buttons or columns.