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.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: web-development10 tags: css, responsive, grid, flexbox, layout, mobile-first, container-queries11---1213## Overview1415Designs 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).1617## When to Use This Skill1819- Building the overall page layout or major sections (header, hero, main content, sidebar, footer).20- The user mentions "responsive", "mobile first", "works on all screen sizes", or provides a wireframe that needs to adapt.21- Creating reusable layout primitives for a design system.22- When performance and simplicity are priorities over heavy layout libraries.2324## Prerequisites2526- CSS file or Tailwind setup in the project.27- Understanding of viewport vs container queries.28- Target breakpoints defined (or the skill will propose sensible ones: 640, 768, 1024, 1280).29- For advanced masonry or subgrid, modern browser support or fallbacks.3031## Steps32331. **Define design tokens**:34 - Create CSS custom properties for spacing scale, container widths, and breakpoints.35 - Example: `--space-4: 1rem; --container-max: 1280px;`36372. **Choose layout primitives**:38 - Use Flexbox for one-dimensional flows (navbars, toolbars, button groups, card rows).39 - Use Grid for two-dimensional layouts (page templates, card grids, dashboards).40 - Consider subgrid and masonry for modern browsers.41423. **Apply mobile-first**:43 - Write base styles for the smallest screen (usually 320-375px).44 - Layer improvements with `min-width` media queries.45 - Never hide critical content on mobile; use progressive disclosure instead.46474. **Implement container queries** (preferred for components):48 - Use `@container` for components that should adapt to their parent width rather than viewport.49 - Fallback to media queries when container queries are not supported.50515. **Build common patterns**:52 - Holy grail (header, sidebar, main, footer)53 - Sidebar + content (collapsible on mobile)54 - Masonry grid55 - Dashboard (multiple resizable panels)56 - Sticky header + scrollable content area57586. **Handle safe areas and notches**:59 - Use `env(safe-area-inset-*)` for mobile devices.60 - Test on iPhone with notch/dynamic island.61627. **Add debug helpers** (optional but useful):63 - A temporary outline or grid overlay toggle for development.64658. **Output**:66 - Complete CSS (or Tailwind config + component classes).67 - HTML structure example.68 - Responsive demo notes.6970## Examples7172**Example: Holy Grail Layout with Sidebar**7374```css75:root {76 --sidebar-width: 280px;77 --header-height: 64px;78}7980.layout {81 display: grid;82 grid-template-areas:83 "header header"84 "sidebar main"85 "footer footer";86 grid-template-rows: var(--header-height) 1fr auto;87 grid-template-columns: var(--sidebar-width) 1fr;88 min-height: 100dvh;89}9091@media (max-width: 768px) {92 .layout {93 grid-template-areas:94 "header"95 "main"96 "footer";97 grid-template-columns: 1fr;98 }99 .sidebar { display: none; } /* or use a drawer pattern */100}101102.header { grid-area: header; }103.sidebar { grid-area: sidebar; }104.main { grid-area: main; }105.footer { grid-area: footer; }106```107108Full 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.109110## Edge Cases & Error Handling111112- **Very narrow screens (320px)**: Ensure no horizontal scroll. Use `overflow-x: hidden` on body and test all components.113- **Container vs viewport**: Prefer container queries for cards/grids that live in sidebars.114- **Print styles**: Provide a separate print stylesheet or `@media print` rules that collapse sidebars and optimize for paper.115- **High zoom levels**: Layouts must not break at 200%+ zoom (reflow, not zoom).116- **Dynamic content**: Account for variable height headers/footers using `min-height: 100dvh` and `grid`.117118## Verification1191201. Open the layout in browser and resize from 320px to 1920px.1212. Use DevTools device toolbar for iPhone, iPad, desktop.1223. Test with real devices if possible.1234. Run Lighthouse — no layout shift issues (CLS < 0.1).1245. Check that all content remains accessible and no overflow at any size.1256. Success: Layout adapts gracefully, no horizontal scroll, content hierarchy preserved on mobile.126127## References128129- [MDN CSS Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout)130- [MDN Flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout)131- [Container Queries](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries)132- [Every Layout](https://every-layout.dev/)133- [CSS-Tricks Complete Guide to Grid](https://css-tricks.com/snippets/css/complete-guide-grid/)