---
name: build-responsive-layouts
description: Builds page layouts that hold up on every screen size using mobile-first CSS, content-based breakpoints, fluid type with clamp, and container queries. Use when a layout overflows on a phone, the user wants a responsive layout, fluid typography, or container queries.
license: MIT
metadata:
  category: design
  tags: "responsive,css,ui"
  author: johnny-bravo
  version: "1.0"
  updated: "2026-11-07"
  status: published
  aliases: "responsive design, container queries, fluid type, mobile-first layout"
  source_url: "https://github.com/wshobson/agents/tree/7e2fb559cf4b824b27f1fec49fe88f7511066d26/plugins/ui-design/skills/responsive-design"
  source_license: MIT
  copyright: "Copyright (c) 2024 Seth Hobson"
  original_author: "Seth Hobson (wshobson/agents, responsive-design)"
  modified: "Adapted by TheSkillVault: rewritten as a short build order (mobile base, fluid type, container queries, overflow checks) with one original example; dropped the breakpoint catalogue and reference files; added gotchas and done-when."
  imported_on: "2026-11-07"
---

# Build responsive layouts

A layout should be readable on a phone and comfortable on a wide screen. Start from the narrow screen. Add rules only when the content needs more room.

## When to use
- A page scrolls sideways on a phone, or text is cut off.
- A card or nav should change when its own box gets wider, not only when the window does.
- Type and spacing jump between two fixed sizes instead of scaling smoothly.

## When not to use
- You only need colour, font and spacing tokens for a theme. That is a separate task.
- The job is a one-off hero headline, not the page layout.

## Steps
1. Write the CSS for the narrow screen first. No media query yet. The column is a single stack, with padding on the page, not a fixed pixel width.
2. Let type and space scale between a minimum and a maximum. `clamp(1rem, 0.9rem + 1vw, 1.35rem)` is enough for body text. Do not use a raw `vw` size with no floor or ceiling.
3. Add a breakpoint only where the content breaks. A common place is when two columns fit without squeezing. Prefer `min-width` queries so the wide rules enhance the mobile base.
4. For a component that is reused in a sidebar and in a full page, set `container-type: inline-size` on the parent. Style the inside with `@container`, not with the viewport.
5. Give images a max width of 100% and a set `aspect-ratio`, so they do not stretch or blow the column out.
6. Check tap targets. Buttons and links need about 44 by 44 pixels of hit area on touch screens.
7. Resize the browser from 320px to a wide desktop. Fix any horizontal scrollbar before you call it done. Check a real phone if you can. A simulator misses some browser chrome.

```css
.card-wrap { container-type: inline-size; }
.card { display: grid; gap: 0.75rem; }
@container (min-width: 28rem) {
  .card { grid-template-columns: 8rem 1fr; align-items: center; }
}
```

## Gotchas
- `100vh` is taller than the visible area on many phones. Use `dvh` or `svh` for full-height panels.
- A wide table or a long word with no break will force sideways scroll. Allow wrap, or let the table scroll inside its own box.
- Fixed widths in pixels fight the fluid layout. Prefer `max-width`, `minmax` and `%`.
- Do not put private screenshots, customer photos or tokens in a public demo of the layout.

## Portability
The CSS works in current browsers. If you use Tailwind, map the same idea onto `min-width` screens and `@container`. If you use another framework, keep the mobile-first order and the container query. Older browsers that lack container queries still get the stacked layout.

## Done when
- At 320px there is no horizontal page scroll.
- Type stays readable, and a repeated component changes with its container.
- Tap targets are large enough to hit with a thumb.

## Example prompt
"This product grid overflows on a phone. Make it one column on small screens, two when the container is wide, with fluid headings."

---
Adapted from "responsive-design" in wshobson/agents (MIT, Copyright (c) 2024 Seth Hobson). See LICENSE.txt.
