Words or parts laid out in a box - a component, a code page, a title, stat, pricing or list card, captions, text elements with a width - or an element that travels from one nested composition into the next. Read before building one, so longer text (another language, new copy) wraps or shrinks instead of overflowing, and to decide what is one component and what is its own element.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Responsive Layout?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/humanharness-responsive-layout)
---
name: responsive-layout
kind: guide
description: Words or parts laid out in a box - a component, a code page, a title, stat, pricing or list card, captions, text elements with a width - or an element that travels from one nested composition into the next. Read before building one, so longer text (another language, new copy) wraps or shrinks instead of overflowing, and to decide what is one component and what is its own element.
---
The copy in a video changes after the code is written: the person rewrites a line, `locales/en.json` is half again as long as the Chinese, a number grows a digit. A component that hardcodes where each word goes breaks on the first change. Write it the way a web page is written: the element's box is fixed, everything inside it flows.
## 1. Decide what is one component and what is its own element
| The parts | Write |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Sit beside or under each other and must make room for each other (title + subtitle + chips, a card's number, label and bar, a grid of tiles) | **One component**, laid out with flex or grid, so a longer title pushes the subtitle down instead of landing on it. |
| Move on their own paths, or the person will retime, restyle or swap one of them alone | **Separate elements**, each with its motion presets: the Inspector edits them, the motion rules measure them, `layout/collision` checks them. |
| Stay on screen across a transition, or travel from one nested composition into the next (a logo that flies into the corner, a card that becomes the next screen's header) | **One element in the parent composition**, over both nested compositions and spanning the cut, keyframed from where it starts to where it lands. Never a copy in each nested composition faded across. If code draws it, it is its own component. |
For the third row, the nested composition it lands in leaves the room empty: lay that composition out with a slot of the travelling element's final size (an empty grid cell or a spacer), and key the element to land on it. The two then agree when the copy on either side changes.
A badge on a tile is still its own element (`"on": "<tile>"`), as the `/component` skill says: layering, not nesting.
## 2. Size from the box, never from 1920 × 1080
- The element's `w` and `h` are the box. Inside it use flex and grid with `%`, `fr`, `gap` and `auto`; no `position: absolute` with pixel offsets for parts that hold text.
- Make the component a size container and size type and spacing from it, so one component works as a full-frame card and as a small tile:
```css
my-card {
display: block;
width: 100%;
height: 100%;
container-type: size;
}
my-card .card {
display: grid;
grid-template-rows: auto auto 1fr;
gap: 4cqmin;
padding: 6cqmin;
}
my-card .title {
font-size: clamp(48px, 9cqmin, 112px);
}
```
`cqmin` is a hundredth of the box's shorter side. Clamp the bottom at 24 px (the `text/too-small` floor at 1080p; nothing below 20 px) and the top at `video.type.display-large` (112 px). This replaces a hand-made `u = Math.min(W, H) / 560` multiplier.
- Type sizes come from the video scale (`ctx.token('video.type.headline')`: display-large 112, display-medium 88, headline 48, body 32), colours, corners and elevation from `var(--md-sys-*)`. The M3 `--md-sys-typescale-*-size` values are sized for phone UI and read too small in a video.
## 3. Let text wrap first, shrink second, never clip
In this order:
1. **Wrap.** `text-wrap: balance` for headlines and short lines, `text-wrap: pretty` for body, `max-width` in `ch` or `em` (about 20 em for a headline, 34 em for body) so a long line wraps before it runs edge to edge. Latin breaks between words, Chinese and Japanese between characters; give URLs, code and long names `overflow-wrap: anywhere`. Korean wants `word-break: keep-all`.
2. **Shrink to fit** only what must stay on one line (a number, a name, a single-word slam) or a block that still does not fit after wrapping: measure, scale its `font-size` down to the room, stop at the 24 px floor. Measure the **final** content, not the frame's: the counted-up number at its target, the typed line in full, every word a swap will show. Fit once when the text or box changes (cache by `${w}x${h}|${text}`), never each frame, or the layout jitters while it moves.
3. **Still does not fit at the floor:** the copy is too long for this element. Say so; do not hide it. No `overflow: hidden`, `text-overflow: ellipsis` or `-webkit-line-clamp` on words a viewer must read: in a video nobody can hover to see the rest.
Text elements follow the same order: one with a `w` gets `"wrap": true`, so a longer translation wraps instead of running out of its box (`layout/overflow`).
Wait for the fonts before the first measure, or the widths are the fallback font's: `ctx.wait(document.fonts.ready)` in the first `renderAt`.
## 4. Lay out the end state, move with transforms
Lay every part out at rest, where it lands, and keep that layout for the element's whole life. Motion is `transform` and `opacity` on top of it (`translate`, `scale`, `rotate`, a clip on the wrapper): it never changes `width`, `height`, `font-size`, `padding` or `gap` while playing. Then text arriving letter by letter, a number counting up or a word swapping does not push its neighbours around (size for the longest state up front: `word-swap` fits its type to its longest word; an invisible copy of the longest state in the same grid cell holds its room).
## 5. Check it with long copy
- Put every word a viewer reads in a prop marked `x-m3e-text` and set it in the element's `attrs`, not only as the schema's default, so `locales/<lang>.json` reaches it.
- `preview_component <tag>` with the longest copy the props allow, and with the composition's other languages: `lint --lang <lang>` for each one, and `look` at the moments where the text is at rest.
- Render lint reads the text inside a component at rest: `layout/overflow` when a run is cut off by a clipping box, hangs past the element or off the card it is drawn in; `text/too-small` and `a11y/contrast` too. Fix each one in the layout, never by clipping harder. Only what is at rest is checked: a part sliding across a transition or still moving inside the component is not. Text meant to run off-frame past the element (a word sweeping across a cut and out) is `"bleed": true` on the element; a crop that is the point (a giant word behind its card) is `"allow": { "overflow": "<why>" }`.
- A part that does not fit at the box `x-moga-preview` gives it is a bug in the component, not in the copy.
`examples/kinetic-type` (`fitEm` in `kinetic-line/kinetic.ts`, `word-swap` fitting to its longest word) and `examples/components/stat-tile` (fitting the final number) show the fitting in code.