CSS Flexbox
Master CSS Flexbox with visual examples, from basic layouts to advanced techniques
Table of Contents
Flex Container
Create Flex Container
Transform any element into a flexible box layout container that arranges its children
Flex Direction
Set the main axis direction to control how flex items flow within the container
Flex Wrap
Control whether flex items wrap to new lines when they overflow the container
Gap
Add consistent spacing between flex items without using margins
Alignment
Justify Content (Main Axis)
Align and distribute flex items along the main axis (horizontal by default)
Align Items (Cross Axis)
Align flex items along the cross axis (vertical by default) within their line
Align Content
Align and distribute wrapped lines of flex items within the container
Flex Items
Flex Grow
Define how much a flex item should grow relative to other items to fill available space
Flex Shrink
Define how much a flex item should shrink relative to other items when space is limited
Flex Basis
Set the initial main size of a flex item before free space is distributed
Flex Shorthand
Combine grow, shrink, and basis values in a single flexible property
Align Self
Override the container's align-items value for individual flex items
Order
Change the visual order of flex items without modifying the HTML structure
Common Patterns
Center Content
Perfect centering technique using flexbox for both horizontal and vertical alignment
Navigation Bar
Common flexbox pattern for creating responsive navigation bars with logo and links
Card Grid
Responsive card layout that automatically adjusts columns based on available space
Sidebar Layout
Classic two-column layout with fixed sidebar and flexible main content area