1---
2name: layout
3description: Improve layout, spacing, and visual rhythm. Fixes monotonous grids, inconsistent spacing, and weak visual hierarchy. Use when the user mentions layout feeling off, spacing issues, visual hierarchy, crowded UI, alignment problems, or wanting better composition.
4version: 2.1.1
5user-invocable: true
6argument-hint: "[target]"
7---
8
9Assess and improve layout and spacing that feels monotonous, crowded, or structurally weak — turning generic arrangements into intentional, rhythmic compositions.
10
11## MANDATORY PREPARATION
12
13Invoke /impeccable — it contains design principles, anti-patterns, and the **Context Gathering Protocol**. Follow the protocol before proceeding — if no design context exists yet, you MUST run /impeccable teach first.
14
15---
16
17## Assess Current Layout
18
19Analyze what's weak about the current spatial design:
20
211. **Spacing**:
22 - Is spacing consistent or arbitrary? (Random padding/margin values)
23 - Is all spacing the same? (Equal padding everywhere = no rhythm)
24 - Are related elements grouped tightly, with generous space between groups?
25
262. **Visual hierarchy**:
27 - Apply the squint test: blur your (metaphorical) eyes — can you still identify the most important element, second most important, and clear groupings?
28 - Is hierarchy achieved effectively? (Space and weight alone can be enough — but is the current approach working?)
29 - Does whitespace guide the eye to what matters?
30
313. **Grid & structure**:
32 - Is there a clear underlying structure, or does the layout feel random?
33 - Are identical card grids used everywhere? (Icon + heading + text, repeated endlessly)
34 - Is everything centered? (Left-aligned with asymmetric layouts feels more designed, but not a hard and fast rule)
35
364. **Rhythm & variety**:
37 - Does the layout have visual rhythm? (Alternating tight/generous spacing)
38 - Is every section structured the same way? (Monotonous repetition)
39 - Are there intentional moments of surprise or emphasis?
40
415. **Density**:
42 - Is the layout too cramped? (Not enough breathing room)
43 - Is the layout too sparse? (Excessive whitespace without purpose)
44 - Does density match the content type? (Data-dense UIs need tighter spacing; marketing pages need more air)
45
46**CRITICAL**: Layout problems are often the root cause of interfaces feeling "off" even when colors and fonts are fine. Space is a design material — use it with intention.
47
48## Plan Layout Improvements
49
50Consult the [spatial design reference](reference/spatial-design.md) from the impeccable skill for detailed guidance on grids, rhythm, and container queries.
51
52Create a systematic plan:
53
54- **Spacing system**: Use a consistent scale — whether that's a framework's built-in scale (e.g., Tailwind), rem-based tokens, or a custom system. The specific values matter less than consistency.
55- **Hierarchy strategy**: How will space communicate importance?
56- **Layout approach**: What structure fits the content? Flex for 1D, Grid for 2D, named areas for complex page layouts.
57- **Rhythm**: Where should spacing be tight vs generous?
58
59## Improve Layout Systematically
60
61### Establish a Spacing System
62
63- Use a consistent spacing scale — framework scales (Tailwind, etc.), rem-based tokens, or a custom scale all work. What matters is that values come from a defined set, not arbitrary numbers.
64- Name tokens semantically if using custom properties: `--space-xs` through `--space-xl`, not `--spacing-8`
65- Use `gap` for sibling spacing instead of margins — eliminates margin collapse hacks
66- Apply `clamp()` for fluid spacing that breathes on larger screens
67
68### Create Visual Rhythm
69
70- **Tight grouping** for related elements (8-12px between siblings)
71- **Generous separation** between distinct sections (48-96px)
72- **Varied spacing** within sections — not every row needs the same gap
73- **Asymmetric compositions** — break the predictable centered-content pattern when it makes sense
74
75### Choose the Right Layout Tool
76
77- **Use Flexbox for 1D layouts**: Rows of items, nav bars, button groups, card contents, most component internals. Flex is simpler and more appropriate for the majority of layout tasks.
78- **Use Grid for 2D layouts**: Page-level structure, dashboards, data-dense interfaces, anything where rows AND columns need coordinated control.
79- **Don't default to Grid** when Flexbox with `flex-wrap` would be simpler and more flexible.
80- Use `repeat(auto-fit, minmax(280px, 1fr))` for responsive grids without breakpoints.
81- Use named grid areas (`grid-template-areas`) for complex page layouts — redefine at breakpoints.
82
83### Break Card Grid Monotony
84
85- Don't default to card grids for everything — spacing and alignment create visual grouping naturally
86- Use cards only when content is truly distinct and actionable — never nest cards inside cards
87- Vary card sizes, span columns, or mix cards with non-card content to break repetition
88
89### Strengthen Visual Hierarchy
90
91- Use the fewest dimensions needed for clear hierarchy. Space alone can be enough — generous whitespace around an element draws the eye. Some of the most sophisticated designs achieve rhythm with just space and weight. Add color or size contrast only when simpler means aren't sufficient.
92- Be aware of reading flow — in LTR languages, the eye naturally scans top-left to bottom-right, but primary action placement depends on context (e.g., bottom-right in dialogs, top in navigation).
93- Create clear content groupings through proximity and separation.
94
95### Manage Depth & Elevation
96
97- Create a semantic z-index scale (dropdown → sticky → modal-backdrop → modal → toast → tooltip)
98- Build a consistent shadow scale (sm → md → lg → xl) — shadows should be subtle
99- Use elevation to reinforce hierarchy, not as decoration
100
101### Optical Adjustments
102
103- If an icon looks visually off-center despite being geometrically centered, nudge it — but only if you're confident it actually looks wrong. Don't adjust speculatively.
104
105**NEVER**:
106- Use arbitrary spacing values outside your scale
107- Make all spacing equal — variety creates hierarchy
108- Wrap everything in cards — not everything needs a container
109- Nest cards inside cards — use spacing and dividers for hierarchy within
110- Use identical card grids everywhere (icon + heading + text, repeated)
111- Center everything — left-aligned with asymmetry feels more designed
112- Default to the hero metric layout (big number, small label, stats, gradient) as a template. If showing real user data, a prominent metric can work — but it should display actual data, not decorative numbers.
113- Default to CSS Grid when Flexbox would be simpler — use the simplest tool for the job
114- Use arbitrary z-index values (999, 9999) — build a semantic scale
115
116## Verify Layout Improvements
117
118- **Squint test**: Can you identify primary, secondary, and groupings with blurred vision?
119- **Rhythm**: Does the page have a satisfying beat of tight and generous spacing?
120- **Hierarchy**: Is the most important content obvious within 2 seconds?
121- **Breathing room**: Does the layout feel comfortable, not cramped or wasteful?
122- **Consistency**: Is the spacing system applied uniformly?
123- **Responsiveness**: Does the layout adapt gracefully across screen sizes?
124
125Remember: Space is the most underused design tool. A layout with the right rhythm and hierarchy can make even simple content feel polished and intentional.