Flex Items

Loading concept...

๐ŸŽญ The Dance Floor Story: Mastering Tailwind Flexbox Items

Imagine youโ€™re a dance instructor. Your dance floor is a flex container, and your dancers are flex items. Today, youโ€™ll learn how to position dancers perfectly on any stage!


๐ŸŽช The Big Picture

Think of a flex container as a dance floor. The dancers (flex items) need to know:

  • Where to stand horizontally (justify-content)
  • Where to stand vertically (align-items)
  • How much space each dancer takes (sizing)
  • Their individual positions (align-self)
  • Their order in the line (order)

Letโ€™s meet each concept through a story!


๐ŸŽฏ Justify Content: Spreading Dancers Across the Stage

The Story: You have 3 dancers on a wide stage. How do they spread out?

The Options

Class What Happens Dancer Positions
justify-start Everyone huddles left ๐Ÿ•บ๐Ÿ’ƒ๐Ÿ•บโ€ฆ
justify-end Everyone huddles right โ€ฆ๐Ÿ•บ๐Ÿ’ƒ๐Ÿ•บ
justify-center Everyone meets middle โ€ฆ๐Ÿ•บ๐Ÿ’ƒ๐Ÿ•บโ€ฆ
justify-between Max space between ๐Ÿ•บโ€ฆ๐Ÿ’ƒโ€ฆ๐Ÿ•บ
justify-around Equal space around โ€ฆ๐Ÿ•บโ€ฆ๐Ÿ’ƒโ€ฆ๐Ÿ•บโ€ฆ
justify-evenly Perfect equal gaps โ€ฆ๐Ÿ•บโ€ฆ๐Ÿ’ƒโ€ฆ๐Ÿ•บโ€ฆ

Code Example

<div class="flex justify-center">
  <div>Dancer 1</div>
  <div>Dancer 2</div>
  <div>Dancer 3</div>
</div>

Pro tip: justify-between is PERFECT for navbars with logo left, menu right!


๐Ÿ“ Align Items: Vertical Positioning

The Story: Now imagine dancers of different heights. Where do their feet land on the vertical line?

The Options

Class What Happens
items-start All touch the ceiling
items-end All touch the floor
items-center All float in middle
items-baseline Text lines up perfectly
items-stretch Everyone stretches tall
graph TD A[items-start] --> B[Top aligned] C[items-center] --> D[Middle aligned] E[items-end] --> F[Bottom aligned] G[items-stretch] --> H[Full height]

Code Example

<div class="flex items-center h-32">
  <div class="h-8">Short</div>
  <div class="h-16">Medium</div>
  <div class="h-24">Tall</div>
</div>

All three boxes align at their centers!


๐ŸŽช Align Content: Multi-Row Dance Formations

The Story: When dancers form multiple ROWS, how do the rows spread out vertically?

โš ๏ธ Important: This only works when you have flex-wrap enabled!

The Options

Class What Rows Do
content-start Rows pack at top
content-end Rows pack at bottom
content-center Rows meet in middle
content-between Max space between rows
content-around Equal space around rows
content-evenly Perfect equal row gaps

Code Example

<div class="flex flex-wrap content-center h-64">
  <div class="w-1/3">Item 1</div>
  <div class="w-1/3">Item 2</div>
  <div class="w-1/3">Item 3</div>
  <div class="w-1/3">Item 4</div>
</div>

The two rows of items center vertically in the container!


๐Ÿ“ Flex Item Sizing: How Big is Each Dancer?

The Story: Three dancers share a stage. Who gets how much room?

Flex Grow: โ€œCan I Take Extra Space?โ€

Class Meaning
grow-0 โ€œNo thanks, Iโ€™m goodโ€
grow โ€œIโ€™ll take whatโ€™s left!โ€
<div class="flex">
  <div class="grow-0 w-20">Fixed</div>
  <div class="grow">I EXPAND!</div>
</div>

Flex Shrink: โ€œCan I Get Smaller?โ€

Class Meaning
shrink-0 โ€œNever! I keep my sizeโ€
shrink โ€œIโ€™ll squeeze if neededโ€

Flex Basis: โ€œMy Starting Sizeโ€

Class Starting Width
basis-0 Start from nothing
basis-1/2 Half the container
basis-full Full width
basis-auto Use my content size

The Magic Combo

<div class="flex">
  <div class="basis-1/4 grow">A</div>
  <div class="basis-1/2">B</div>
  <div class="basis-1/4 grow">C</div>
</div>

A and C split extra space. B stays at half!


๐ŸŽญ Align Self: One Rebel Dancer

The Story: What if ONE dancer wants to stand differently from everyone else?

Override the Group!

Class This Item Does
self-auto Follow the group
self-start Jump to top
self-end Drop to bottom
self-center Float in middle
self-stretch Stretch full height
self-baseline Align text baseline

Code Example

<div class="flex items-start h-32">
  <div>Normal (top)</div>
  <div class="self-end">I'm at bottom!</div>
  <div>Normal (top)</div>
</div>

Middle item rebels and goes to the bottom!


๐Ÿ”ข Order Utilities: Change the Dance Order

The Story: Dancers line up. But wait! We want to rearrange without changing the HTML!

How Order Works

  • Default order is 0 for everyone
  • Lower numbers come FIRST
  • Higher numbers come LAST
  • Negative numbers go to the FRONT
Class Order Value
order-first -9999 (always first)
order-last 9999 (always last)
order-none 0 (default)
order-1 through order-12 1 to 12
-order-1 -1 (before default)

Code Example

<div class="flex">
  <div class="order-3">I appear 3rd</div>
  <div class="order-1">I appear 1st</div>
  <div class="order-2">I appear 2nd</div>
</div>

Even though โ€œ3rdโ€ is first in HTML, it shows last!

Real World Use

<!-- Mobile: Image on top, text below -->
<!-- Desktop: Text left, image right -->
<div class="flex flex-col md:flex-row">
  <img class="order-1 md:order-2" />
  <p class="order-2 md:order-1">Text</p>
</div>

๐ŸŽ“ Quick Reference Card

graph TD A[Flex Container] --> B[justify-content] A --> C[align-items] A --> D[align-content] E[Flex Items] --> F[grow/shrink/basis] E --> G[align-self] E --> H[order] B --> I[Main Axis: โ†โ†’] C --> J[Cross Axis: โ†‘โ†“] G --> K[Override align-items]

๐Ÿš€ Putting It All Together

Hereโ€™s a real navbar example using everything:

<nav class="flex items-center justify-between">
  <div class="order-1">
    LOGO
  </div>
  <div class="order-3 md:order-2 grow flex
              justify-center">
    Menu Links
  </div>
  <div class="order-2 md:order-3">
    Login Button
  </div>
</nav>

What happens:

  • justify-between โ†’ Logo left, button right
  • items-center โ†’ Everything vertically centered
  • Middle section grow โ†’ Takes remaining space
  • order โ†’ Reorders on mobile vs desktop!

๐Ÿ’ก Remember This!

When You Want Toโ€ฆ Use This
Spread items horizontally justify-*
Align items vertically items-*
Space multiple rows content-*
Make item grow/shrink grow, shrink, basis-*
Override one itemโ€™s alignment self-*
Reorder without changing HTML order-*

๐ŸŽ‰ You Did It!

You now understand:

  • โœ… justify-content (horizontal spreading)
  • โœ… align-items (vertical alignment)
  • โœ… align-content (multi-row spacing)
  • โœ… Flex sizing (grow, shrink, basis)
  • โœ… align-self (individual override)
  • โœ… order (visual reordering)

Youโ€™re ready to build any layout! ๐Ÿ•บ๐Ÿ’ƒ๐ŸŽญ

Loading story...

No Story Available

This concept doesn't have a story yet.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

Interactive Preview

Interactive - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Interactive Content

This concept doesn't have interactive content yet.

Cheatsheet Preview

Cheatsheet - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Cheatsheet Available

This concept doesn't have a cheatsheet yet.

Quiz Preview

Quiz - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Quiz Available

This concept doesn't have a quiz yet.