Flexbox, Grid and Responsive Design
Build layouts that work from a budget Android phone to a wide monitor using Flexbox, Grid and media queries.
Beginner · about 8 hours · difficulty 2/5
Learn first: CSS Fundamentals
Most Indian users reach your app on a phone, often a small screen on a slow network. Mobile-first layout is not optional.
Flexbox for one dimension
Rows or columns of items: navbars, button groups, card footers. Learn justify-content, align-items, gap, flex-wrap and flex: 1.
Grid for two dimensions
Page shells, dashboards and card galleries. grid-template-columns with repeat(auto-fit, minmax(240px, 1fr)) gives you a responsive gallery with no media queries at all.
Responsive techniques
- Start with the mobile layout, then add min-width media queries for larger screens.
- Use fluid sizing with clamp() for type and spacing.
- Make images responsive with max-width: 100% and the srcset attribute.
- Container queries let a component adapt to its own width rather than the viewport.
Test for real
Use DevTools device mode, but also open the app on an actual phone over your local network. Throttle the network to "Slow 4G" to feel what your users feel.
Pitfalls
- Fixed pixel widths that cause horizontal scrolling on phones.
- Tap targets smaller than about 44px.
- Desktop-first CSS that piles up overrides for mobile.
You are ready to move on when you can rebuild a dashboard layout (sidebar, header, card grid) that collapses cleanly to a single column on a 360px wide screen.
Key concepts
- Flexbox
- CSS Grid
- Mobile-first media queries
- Fluid type with clamp()
- Responsive images
- Container queries
- Device testing and throttling
Mini project
Build a responsive job listings page: filter sidebar on desktop that becomes a collapsible panel on mobile, and a card grid of internships with stipend in rupees, location and deadline.
Check yourself
When would you reach for Grid instead of Flexbox? Give one layout example for each.
Free resources
- A Complete Guide to Flexbox (CSS-Tricks)
- A Complete Guide to CSS Grid (CSS-Tricks)
- Learn Responsive Design (web.dev)