πŸ”° Tailwind CSS: Padding and Background Colors

What does p-8 mean?

πŸ”’ p-8 = padding: 2rem; β†’ Since 1rem = 16px, that’s 32px padding on all sides.

πŸ”„ Variations of p

Class Meaning
p-8padding on all sides
pt-8padding-top
pb-8padding-bottom
pl-8padding-left
pr-8padding-right
px-8padding left + right
py-8padding top + bottom

βœ… Example Box

This box has 32px padding on all sides using p-8.

What does text-3xl mean?

πŸ”€ text-3xl sets the font size to 1.875rem (about 30px).

This is text-3xl size text β€” big and bold!

πŸ“ Tailwind Text Size Scale:

Class Font Size (rem) Font Size (px) Description
text-xs0.75rem12pxExtra small
text-sm0.875rem14pxSmall
text-base1rem16pxBase (normal) size
text-lg1.125rem18pxLarge
text-xl1.25rem20pxExtra large
text-2xl1.5rem24px2Γ— Extra large
text-3xl1.875rem30px3Γ— Extra large
text-4xl2.25rem36px4Γ— Extra large
text-5xl3rem48px5Γ— Extra large
text-6xl3.75rem60px6Γ— Extra large
text-7xl4.5rem72px7Γ— Extra large
text-8xl6rem96px8Γ— Extra large
text-9xl8rem128px9Γ— Extra large

🎨 What does bg-gray-100 mean?

Tailwind uses a color scale ranging from 50 (lightest) to 950 (darkest). That’s 19 levels per color.

bg-gray-100
bg-gray-400
bg-gray-800

Example gray shades visually:

Shade Example Color Description
gray-50 Very Light
gray-100 Light
gray-400 Medium
gray-800 Dark
gray-950 Very Dark

🧱 What does border-t-2 mean?

So border-t-2 means: add a 2px border only to the top of the element.

This box has a 2px top border using border-t-2.

πŸ“ Tailwind Border Thickness Classes

Class Thickness Description
border1pxDefault (1px on all sides)
border-t-22pxTop border only
border-b-44pxBottom border only
border-l-88pxLeft border only

πŸ”΅ What does rounded mean?

rounded
rounded-md
rounded-full

πŸ“ Common Rounded Classes

Class Effect
roundedSmall border radius
rounded-mdMedium border radius
rounded-lgLarge border radius
rounded-fullCircle/fully rounded (useful for avatars)

πŸ”€ What does font mean?

Here are some examples:

font-thin (100)

font-normal (400)

font-semibold (600)

font-bold (700)

font-black (900)

πŸ“ Font Weight Classes

Class Weight Description
font-thin100Very light
font-normal400Regular
font-semibold600Semi-bold
font-bold700Bold
font-black900Extra bold

🧭 What do x and y mean in Tailwind?

px-8 py-2 (Horizontal: 32px, Vertical: 8px)
mx-8 my-4 (Margin Left/Right: 32px, Top/Bottom: 16px)

πŸ“ Axis Shorthand Classes

Class Effect
px-8Padding left & right (32px)
py-4Padding top & bottom (16px)
mx-6Margin left & right (24px)
my-2Margin top & bottom (8px)

πŸ“Œ What does position do in Tailwind CSS?

Tailwind provides utility classes to control how elements are positioned on the screen.

🧱 Position Classes

This box is relative (positioned normally).

absolute (top-right)
fixed (always at bottom-right)
sticky header (sticks to top)

Scroll me to see sticky effect

πŸ“‹ Summary Table

Class Meaning Description
staticDefaultElement stays in normal flow (no positioning)
relativeRelativeOffset from normal position using top/right/bottom/left
absoluteAbsolutePlaced inside the nearest ancestor with relative/absolute/fixed
fixedFixedStays in place even during scroll (relative to viewport)
stickyStickyScrolls until it reaches a scroll position, then sticks

🧱 What are block, inline, and inline-block in Tailwind?

These utility classes control how elements flow and wrap in the layout. Each has different behavior.

πŸ“¦ Visual Examples

πŸ”Ή block (takes full width)

Block element Another block element

πŸ”Έ inline (sits next to each other)

Inline 1 Inline 2

πŸ”Έ inline-block (sits inline but allows box sizing)

Inline-Block 1 Inline-Block 2

πŸ“‹ Summary Table

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

🧱 What does flex mean in Tailwind CSS?

Tailwind uses the flex utility to apply flexbox layout to elements. Flexbox helps align, distribute, and arrange elements responsively.

πŸ“¦ Basic Usage

1
2
3

πŸ”Ή flex creates a row by default.

A
B
C

πŸ”Έ flex-col stacks items vertically.

πŸ“‹ Display Classes

Class Effect CSS Equivalent
blockBlock-level boxdisplay: block;
inline-blockInline + blockdisplay: inline-block;
flexFlexbox containerdisplay: flex;
inline-flexInline flex containerdisplay: inline-flex;
gridGrid layoutdisplay: grid;
hiddenHide elementdisplay: none;

πŸ“ Direction Classes

Class Direction CSS
flex-rowHorizontalflex-direction: row;
flex-colVerticalflex-direction: column;
flex-row-reverseRow reversedflex-direction: row-reverse;
flex-col-reverseColumn reversedflex-direction: column-reverse;

πŸ”² What is 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.

πŸ“¦ Basic Grid Example

1
2
3

Above uses grid grid-cols-3 β†’ creates 3 equal-width columns.

πŸ“ Common Grid Classes

Class Effect CSS Equivalent
gridEnables grid displaydisplay: grid;
grid-cols-22 equal columnsgrid-template-columns: repeat(2, 1fr);
grid-cols-44 equal columnsgrid-template-columns: repeat(4, 1fr);
gap-4Adds spacing between itemsgap: 1rem;
col-span-2Item spans 2 columnsgrid-column: span 2 / span 2;

πŸ”’ Grid with Different Column Counts

A
B
1
2
3
4

πŸ“ Spanning Columns

Span 2 columns
Normal

πŸ” What does 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.

βœ… What it means:

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

🧾 This is an example paragraph using leading-relaxed. Notice how the lines are comfortably spaced, which improves readability for longer content such as articles, documentation, or educational materials.

πŸ“š Common leading-* values in Tailwind:

Class Line Height Description
leading-none1No spacing between lines
leading-tight1.25Tighter line spacing
leading-snug1.375Slightly tight
leading-normal1.5Normal spacing
leading-relaxed1.625Relaxed and readable βœ…
leading-loose2Very loose spacing

🧠 Why use leading-relaxed?

πŸŒ‘ What is 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.

βœ… Common Tailwind Box Shadow Classes

Class Description
shadow-smSmall shadow
shadowDefault medium shadow
shadow-mdMedium shadow
shadow-lgLarge shadow
shadow-xlExtra large shadow
shadow-2xlHuge shadow
shadow-innerInner shadow
shadow-noneRemoves shadow

✨ Example Button with Shadow

This button uses shadow-lg to give it a large shadow:

πŸ“ Try It Yourself

πŸ–±οΈ Tailwind CSS: 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 selected

focus:ring-2 and focus:ring-blue-500 add a blue border ring when focused.

πŸš€ transform β€” Move, scale, or rotate elements

Hover me!

The transform class enables transformations like:

🧰 Common Transform Utilities

Class Effect
scale-110Scales to 110%
rotate-6Rotates 6Β°
translate-x-2Moves 0.5rem to right
-translate-y-1Moves 0.25rem upward

✨ Tips:

πŸ“± Tailwind CSS Responsive Breakpoints (Screen Sizes)

Tailwind makes responsive design super easy using mobile-first breakpoints. You can apply styles that change based on the device’s screen width.

πŸ”Ή Format:

screen-size:class

For example: md:text-xl means "apply text-xl when the screen is medium or larger".

πŸ“ Default Breakpoints in Tailwind:

Prefix Min Width Device Type
sm640pxSmall devices (e.g., phones)
md768pxMedium devices (e.g., tablets)
lg1024pxLarge devices (e.g., laptops)
xl1280pxExtra large (e.g., desktops)
2xl1536pxBig screens (e.g., TVs, monitors)

🎯 Example

This heading will be small on phones, but grow on bigger screens:

🌟 I grow bigger on larger screens!

🧠 Tips:

πŸ™ˆ Built-in Visibility Utility Classes in Tailwind CSS

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;.

invisible vs. visible

Use invisible to hide an element but still keep its space in the layout. Use visible to reverse it.

I'm visible

invisible = visibility: hidden;    visible = visibility: visible;

πŸ“± Responsive Visibility

You can use responsive prefixes like md:hidden or lg:visible to show/hide elements on specific screen sizes.

I disappear on medium screens and above (using md:hidden).

πŸ“‹ Summary of Visibility Utilities

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.

Understanding md in Tailwind CSS

🟒 1. md 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)."

πŸ”Ή Example:

<div class="bg-red-500 md:bg-green-500">
  • On small screens β†’ bg-red-500
  • On screens β‰₯ 768px β†’ bg-green-500

πŸ“ Tailwind's Default Breakpoints:

Prefix Min Width Device Type
sm640pxSmall phones
md768pxTablets / Small laptops
lg1024pxLaptops / Desktops
xl1280pxLarge desktops
2xl1536pxVery large screens

πŸ”΅ 2. 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.

πŸ”Ή Example:

<div class="max-w-md">

This sets:

max-width: 28rem; /* which is 448px */

πŸ“ Tailwind width scale (common values):

Class Value
max-w-sm24rem (384px)
max-w-md28rem (448px)
max-w-lg32rem (512px)
max-w-xl36rem (576px)

🧠 Summary:

Use Case Meaning
md: (prefix)Breakpoint β‰₯768px
max-w-mdSize = 28rem (448px)

Understanding space-y-6 in Tailwind CSS

πŸ”Ή What is 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 */
    }

πŸ§ͺ Example

The following layout stacks three boxes vertically with 24px spacing between them using space-y-6:

Box 1
Box 2
Box 3

πŸ“ Tailwind Spacing Scale

You can adjust spacing with different values like space-y-1, space-y-2, etc.

Class Spacing (rem) Pixels
space-y-10.25rem4px
space-y-20.5rem8px
space-y-41rem16px
space-y-61.5rem24px
space-y-82rem32px
space-y-102.5rem40px

πŸ” Bonus: Horizontal Spacing

You can also use space-x-6 to add horizontal spacing between inline elements, like buttons or columns.