Overview
Designs and implements robust, maintainable responsive page and component layouts using modern CSS (Grid for 2D, Flexbox for 1D), mobile-first methodology, CSS custom property design tokens for spacing and breakpoints, container queries where appropriate, and common layout patterns (sidebar, holy grail, masonry, dashboard).
When to Use This Skill
- Building the overall page layout or major sections (header, hero, main content, sidebar, footer).
- The user mentions "responsive", "mobile first", "works on all screen sizes", or provides a wireframe that needs to adapt.
- Creating reusable layout primitives for a design system.
- When performance and simplicity are priorities over heavy layout libraries.
Prerequisites
- CSS file or Tailwind setup in the project.
- Understanding of viewport vs container queries.
- Target breakpoints defined (or the skill will propose sensible ones: 640, 768, 1024, 1280).
- For advanced masonry or subgrid, modern browser support or fallbacks.
Steps
Define design tokens:
- Create CSS custom properties for spacing scale, container widths, and breakpoints.
- Example:
--space-4: 1rem; --container-max: 1280px;
Choose layout primitives:
- Use Flexbox for one-dimensional flows (navbars, toolbars, button groups, card rows).
- Use Grid for two-dimensional layouts (page templates, card grids, dashboards).
- Consider subgrid and masonry for modern browsers.
Apply mobile-first:
- Write base styles for the smallest screen (usually 320-375px).
- Layer improvements with
min-width media queries.
- Never hide critical content on mobile; use progressive disclosure instead.
Implement container queries (preferred for components):
- Use
@container for components that should adapt to their parent width rather than viewport.
- Fallback to media queries when container queries are not supported.
Build common patterns:
- Holy grail (header, sidebar, main, footer)
- Sidebar + content (collapsible on mobile)
- Masonry grid
- Dashboard (multiple resizable panels)
- Sticky header + scrollable content area
Handle safe areas and notches:
- Use
env(safe-area-inset-*) for mobile devices.
- Test on iPhone with notch/dynamic island.
Add debug helpers (optional but useful):
- A temporary outline or grid overlay toggle for development.
Output:
- Complete CSS (or Tailwind config + component classes).
- HTML structure example.
- Responsive demo notes.
Examples
Example: Holy Grail Layout with Sidebar
:root {
--sidebar-width: 280px;
--header-height: 64px;
}
.layout {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
grid-template-rows: var(--header-height) 1fr auto;
grid-template-columns: var(--sidebar-width) 1fr;
min-height: 100dvh;
}
@media (max-width: 768px) {
.layout {
grid-template-areas:
"header"
"main"
"footer";
grid-template-columns: 1fr;
}
.sidebar { display: none; } /* or use a drawer pattern */
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
Full HTML + more patterns (masonry using grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) with masonry-auto-flow or JS fallback) included in the skill output.
Edge Cases & Error Handling
- Very narrow screens (320px): Ensure no horizontal scroll. Use
overflow-x: hidden on body and test all components.
- Container vs viewport: Prefer container queries for cards/grids that live in sidebars.
- Print styles: Provide a separate print stylesheet or
@media print rules that collapse sidebars and optimize for paper.
- High zoom levels: Layouts must not break at 200%+ zoom (reflow, not zoom).
- Dynamic content: Account for variable height headers/footers using
min-height: 100dvh and grid.
Verification
- Open the layout in browser and resize from 320px to 1920px.
- Use DevTools device toolbar for iPhone, iPad, desktop.
- Test with real devices if possible.
- Run Lighthouse — no layout shift issues (CLS < 0.1).
- Check that all content remains accessible and no overflow at any size.
- Success: Layout adapts gracefully, no horizontal scroll, content hierarchy preserved on mobile.
References
1---2name: responsive-layout-system3description: Creates a responsive layout using CSS Grid and Flexbox with mobile-first breakpoints. Use when building page layouts that must work across all screen sizes.4license: Apache-2.05---67## Overview89Designs and implements robust, maintainable responsive page and component layouts using modern CSS (Grid for 2D, Flexbox for 1D), mobile-first methodology, CSS custom property design tokens for spacing and breakpoints, container queries where appropriate, and common layout patterns (sidebar, holy grail, masonry, dashboard).1011## When to Use This Skill1213- Building the overall page layout or major sections (header, hero, main content, sidebar, footer).14- The user mentions "responsive", "mobile first", "works on all screen sizes", or provides a wireframe that needs to adapt.15- Creating reusable layout primitives for a design system.16- When performance and simplicity are priorities over heavy layout libraries.1718## Prerequisites1920- CSS file or Tailwind setup in the project.21- Understanding of viewport vs container queries.22- Target breakpoints defined (or the skill will propose sensible ones: 640, 768, 1024, 1280).23- For advanced masonry or subgrid, modern browser support or fallbacks.2425## Steps26271. **Define design tokens**:28 - Create CSS custom properties for spacing scale, container widths, and breakpoints.29 - Example: `--space-4: 1rem; --container-max: 1280px;`30312. **Choose layout primitives**:32 - Use Flexbox for one-dimensional flows (navbars, toolbars, button groups, card rows).33 - Use Grid for two-dimensional layouts (page templates, card grids, dashboards).34 - Consider subgrid and masonry for modern browsers.35363. **Apply mobile-first**:37 - Write base styles for the smallest screen (usually 320-375px).38 - Layer improvements with `min-width` media queries.39 - Never hide critical content on mobile; use progressive disclosure instead.40414. **Implement container queries** (preferred for components):42 - Use `@container` for components that should adapt to their parent width rather than viewport.43 - Fallback to media queries when container queries are not supported.44455. **Build common patterns**:46 - Holy grail (header, sidebar, main, footer)47 - Sidebar + content (collapsible on mobile)48 - Masonry grid49 - Dashboard (multiple resizable panels)50 - Sticky header + scrollable content area51526. **Handle safe areas and notches**:53 - Use `env(safe-area-inset-*)` for mobile devices.54 - Test on iPhone with notch/dynamic island.55567. **Add debug helpers** (optional but useful):57 - A temporary outline or grid overlay toggle for development.58598. **Output**:60 - Complete CSS (or Tailwind config + component classes).61 - HTML structure example.62 - Responsive demo notes.6364## Examples6566**Example: Holy Grail Layout with Sidebar**6768```css69:root {70 --sidebar-width: 280px;71 --header-height: 64px;72}7374.layout {75 display: grid;76 grid-template-areas:77 "header header"78 "sidebar main"79 "footer footer";80 grid-template-rows: var(--header-height) 1fr auto;81 grid-template-columns: var(--sidebar-width) 1fr;82 min-height: 100dvh;83}8485@media (max-width: 768px) {86 .layout {87 grid-template-areas:88 "header"89 "main"90 "footer";91 grid-template-columns: 1fr;92 }93 .sidebar { display: none; } /* or use a drawer pattern */94}9596.header { grid-area: header; }97.sidebar { grid-area: sidebar; }98.main { grid-area: main; }99.footer { grid-area: footer; }100```101102Full HTML + more patterns (masonry using `grid-template-columns: repeat(auto-fill, minmax(240px, 1fr))` with `masonry-auto-flow` or JS fallback) included in the skill output.103104## Edge Cases & Error Handling105106- **Very narrow screens (320px)**: Ensure no horizontal scroll. Use `overflow-x: hidden` on body and test all components.107- **Container vs viewport**: Prefer container queries for cards/grids that live in sidebars.108- **Print styles**: Provide a separate print stylesheet or `@media print` rules that collapse sidebars and optimize for paper.109- **High zoom levels**: Layouts must not break at 200%+ zoom (reflow, not zoom).110- **Dynamic content**: Account for variable height headers/footers using `min-height: 100dvh` and `grid`.111112## Verification1131141. Open the layout in browser and resize from 320px to 1920px.1152. Use DevTools device toolbar for iPhone, iPad, desktop.1163. Test with real devices if possible.1174. Run Lighthouse — no layout shift issues (CLS < 0.1).1185. Check that all content remains accessible and no overflow at any size.1196. Success: Layout adapts gracefully, no horizontal scroll, content hierarchy preserved on mobile.120121## References122123- [MDN CSS Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout)124- [MDN Flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout)125- [Container Queries](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries)126- [Every Layout](https://every-layout.dev/)127- [CSS-Tricks Complete Guide to Grid](https://css-tricks.com/snippets/css/complete-guide-grid/)