Designing a responsive Grid with breakpoint props
abstracting responsive CSS behind a clean API.
accept per-breakpoint column props, map them to CSS Grid and media queries or container queries, expose a gap prop.
leaking raw media-query CSS to every consumer.
What's really being asked
This checks whether you can design a declarative layout API that abstracts responsive CSS, so consumers describe intent (columns per breakpoint) rather than writing media queries themselves.
The full answer
The Grid should accept a responsive column specification, for example a columns prop that is either a single number or an object mapping breakpoints like mobile, tablet, and desktop to column counts. Internally it uses CSS Grid, setting grid-template-columns to repeat the requested count, and applies the per-breakpoint values via media queries or, better, container queries so the grid responds to its own container rather than the viewport. Expose a gap prop wired to the design system spacing scale for consistent gutters. Children are passed as-is and flow into the grid tracks, so consumers do not manage placement. The key is that all the responsive CSS lives inside the component; the consumer only declares how many columns they want at each size. Optionally support spanning by pairing with a GridItem that accepts its own breakpoint span.
The mistakes people make
Hardcoding one column count with no responsiveness. Making consumers write their own media queries, which defeats the abstraction. Using floats or manual width math instead of CSS Grid. Tying gap to arbitrary pixels instead of the spacing tokens.
What usually comes next
Container queries versus viewport media queries, and when each is appropriate. How do you support items that span multiple columns? How do you keep generated CSS small with many breakpoints?
A concrete example
A consumer writes Grid with columns set to one on mobile, two on tablet, and four on desktop, plus a gap token of md. The component emits CSS Grid rules that switch grid-template-columns at each breakpoint, and the children reflow from a single column on phones to four across on desktop, with the consumer never touching a media query.
Interview question
What is the main benefit of a Grid component that accepts per-breakpoint column counts as props instead of exposing raw CSS?
- a.It guarantees the grid never needs a gap between items
- b.Consumers declare layout intent while the component encapsulates all responsive CSSCorrect
- c.It forces every layout to use exactly one column on all screens
- d.It eliminates the need for CSS Grid or Flexbox entirely
Why? this is the answer
The abstraction lets consumers say how many columns per breakpoint while the component owns the media queries and grid CSS. It still uses CSS Grid internally and still supports gaps and multiple columns.
Just read this? Test yourself on what you have been reading.
Read the original → mui.com
- #responsive-design
- #css-grid
- #layout
- #component-api
- #breakpoints
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles