Mastering Flexbox for Modern Web Design
HTML5 & CSS3
SCSS
JavaScript
TypeScript
React
Next.js
Tailwind CSS
Bootstrap
ShadCN UI
Styled Components
GSAP
Framer Motion
Vite
Shopify themes
i18next & RTL
Recharts
Chart.js
SaaS dashboards
Figma to UI
Dark / light mode
4+ years
Vistothemes
Freelance UI
NFT & crypto UI
eCommerce UI
WordPress CSS
Remote-ready
Muhammad Shahzaib
Pixel-perfect
Component architecture
Live demos
HTML5 & CSS3
SCSS
JavaScript
TypeScript
React
Next.js
Tailwind CSS
Bootstrap
ShadCN UI
Styled Components
GSAP
Framer Motion
Vite
Shopify themes
i18next & RTL
Recharts
Chart.js
SaaS dashboards
Figma to UI
Dark / light mode
4+ years
Vistothemes
Freelance UI
NFT & crypto UI
eCommerce UI
WordPress CSS
Remote-ready
Muhammad Shahzaib
Pixel-perfect
Component architecture
Live demos

Flexbox is still the fastest way to solve one-dimensional layout problems — rows and columns of items that need to align, distribute space, or wrap predictably. Grid is better for two-dimensional page layout, but for navbars, cards, form rows, and button groups, flex is usually the right tool.
The container properties that matter
display: flex turns on flex layout for direct children. justify-content controls spacing along the main axis (start, center, space-between, space-around). align-items controls alignment on the cross axis. flex-wrap: wrap lets items drop to a new line instead of shrinking forever — almost always what you want on a real page.
The item properties that matter
flex-grow, flex-shrink, and flex-basis (usually written as the flex shorthand) decide how items share leftover space. flex: 1 is the one to remember — it makes an item grow and shrink equally with its siblings, which is how most 'equal width columns' layouts are built.
A pattern worth memorizing
Centering something both horizontally and vertically is the classic flex demo for a reason: display: flex; align-items: center; justify-content: center; on the parent solves it in three lines, no magic numbers, no absolute positioning hacks.
.card-row {
display: flex;
flex-wrap: wrap;
gap: 24px;
justify-content: center;
}
.card {
flex: 1 1 280px; /* grow, shrink, min width before wrapping */
}
.center-anything {
display: flex;
align-items: center;
justify-content: center;
}Reach for flex first when you're laying out a single row or column of items. If you find yourself fighting it to build a full page grid with both rows and columns that need to align together, that's the signal to switch to CSS Grid instead.
← back to all writingMuhammad Shahzaib
Frontend Developer
React & Next.js
TypeScript
Tailwind CSS
Muhammad Shahzaib
SaaS dashboards
Shopify themes
GSAP & Framer
Muhammad Shahzaib
ShadCN UI
RTL & i18next
Figma to UI
Muhammad Shahzaib
4+ years
Vistothemes
Freelance UI
Muhammad Shahzaib
Remote work
pixel-perfect
Muhammad Shahzaib
Frontend Developer
React & Next.js
TypeScript
Tailwind CSS
Muhammad Shahzaib
SaaS dashboards
Shopify themes
GSAP & Framer
Muhammad Shahzaib
ShadCN UI
RTL & i18next
UI-only scope
Muhammad Shahzaib
your mockups
production UI
Muhammad Shahzaib
Muhammad Shahzaib
Frontend Developer
React & Next.js
TypeScript
Tailwind CSS
Muhammad Shahzaib
SaaS dashboards
Shopify themes
GSAP & Framer
Muhammad Shahzaib
ShadCN UI
RTL & i18next
Figma to UI
Muhammad Shahzaib
4+ years
Vistothemes
Freelance UI
Muhammad Shahzaib
Remote work
pixel-perfect
Muhammad Shahzaib
Frontend Developer
React & Next.js
TypeScript
Tailwind CSS
Muhammad Shahzaib
SaaS dashboards
Shopify themes
GSAP & Framer
Muhammad Shahzaib
ShadCN UI
RTL & i18next
UI-only scope
Muhammad Shahzaib
your mockups
production UI
Muhammad Shahzaib
Muhammad Shahzaib
Frontend Developer
React & Next.js
TypeScript
Tailwind CSS
Muhammad Shahzaib
SaaS dashboards
Shopify themes
GSAP & Framer
Muhammad Shahzaib
ShadCN UI
RTL & i18next
Figma to UI
Muhammad Shahzaib
4+ years
Vistothemes
Freelance UI
Muhammad Shahzaib
Remote work
pixel-perfect
Muhammad Shahzaib
Frontend Developer
React & Next.js
TypeScript
Tailwind CSS
Muhammad Shahzaib
SaaS dashboards
Shopify themes
GSAP & Framer
Muhammad Shahzaib
ShadCN UI
RTL & i18next
UI-only scope
Muhammad Shahzaib
your mockups
production UI
Muhammad Shahzaib
Muhammad Shahzaib
Frontend Developer
React & Next.js
TypeScript
Tailwind CSS
Muhammad Shahzaib
SaaS dashboards
Shopify themes
GSAP & Framer
Muhammad Shahzaib
ShadCN UI
RTL & i18next
Figma to UI
Muhammad Shahzaib
4+ years
Vistothemes
Freelance UI
Muhammad Shahzaib
Remote work
pixel-perfect
Muhammad Shahzaib
Frontend Developer
React & Next.js
TypeScript
Tailwind CSS
Muhammad Shahzaib
SaaS dashboards
Shopify themes
GSAP & Framer
Muhammad Shahzaib
ShadCN UI
RTL & i18next
UI-only scope
Muhammad Shahzaib
your mockups
production UI
Muhammad Shahzaib