UtilitiesPremium

Grid Morph

A tile mosaic that stacks in a column inside 200 px, goes to two columns at 220 px and, at 300 px, moves to three columns while giving the first tile the room of four. CSS only.

CSS@containerGrid

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Utilities has 43 effects, including 3 free. Explore the category →

3 usage examples

Home screen of a wildlife park's app, phone upright then sideways — Grid Morph example 1

① Home screen of a wildlife park's app, phone upright then sideways

WhenPhone upright, the app's screen is 168 px wide: the six sections stack, otter feeding first. The visitor turns the phone sideways: 318 px, three columns, and “11:15 am, otter feeding” becomes the large tile, with the pool and the countdown that stayed hidden.
WhyOne grid for both orientations; the news of the moment gets the width as soon as there is some.
SettingsOne root filling the screen of a phone drawn by the page; “Rotate” changes the screen size (168 ↔ 318 px) with a quarter turn. Until it is clicked, a timer turns the phone every 0.7 s for the capture. Rows cut to 36 px, white tiles, yellow first tile; the page enlarges the time in the large tile with its own @container grm (min-width: 300px) rule.
Key pad of a market till that tightens when the ticket opens — a cheesemonger's tablet — Grid Morph example 2

② Key pad of a market till that tightens when the ticket opens — a cheesemonger's tablet

WhenThe pad fills the tablet: three columns, “Comté” as the big key with its “best seller” note. The cheesemonger taps “Tomme”: the item is added, the ticket opens on the right (232 px), the pad is left with 288 px and moves to two columns of equal keys.
WhyAll six keys stay under the finger, ticket open or closed, without planning two layouts.
SettingsTiles written as <button class="grm-item"> with a focus outline added by the page. Adding to the ticket and opening it is the page's script; the component only reads the width it has left.
Sections of a dairy co-op's intranet — the sidebar widens on hover — Grid Morph example 3

③ Sections of a dairy co-op's intranet — the sidebar widens on hover

WhenFolded, the bar is 128 px: six sections in a column. When the pointer enters it, or the keyboard reaches it, it opens to 316 px: the sections settle into a mosaic and “Collection” becomes a big yellow tile showing the morning's volume.
WhyThe folded bar leaves room for the day's dashboard; open, it shows all six sections and the figure that matters at once.
SettingsTiles written as links. Bar width animated by the page (:hover and :focus-within, 0.28 s); 42 px rows; tints replaced with a plain green and a yellow for the first tile.

How it works

.grm-grid is a CSS grid: one column, fixed 60 px rows (grid-auto-rows), 8 px between tiles, 12 px around. Each .grm-item centres its content and gets one of six tints (purple, pink, cyan, amber, green, red at 15 %), handed out by :nth-child(6n+…): the seventh tile takes the first one's colour again.

The root .fx-0754-root carries container: grm / inline-size. At 220 px wide, @container grm writes repeat(2, 1fr); at 300 px, repeat(3, 1fr), and the .grm-item:first-child rule stretches the first tile over two columns and two rows. With six tiles this makes a full square of three rows: the big one, two small ones to its right, three underneath. The same threshold reveals .grm-span, a bit of text kept hidden in the first tile until then.

Height changes with the column count: 424 px as a column, 220 px at two as at three columns for six tiles. The switch is abrupt: the component has neither transition nor script, tiles jump from one layout to the next.

Accessibility

  • Order kept: the grid moves nothing in the HTML; a screen reader and the Tab key go through the tiles in the order you wrote them, whatever the layout.
  • Inert tiles by default: they are divs, so nothing is focusable. If a tile leads somewhere, write it as <a class="grm-item"> or <button class="grm-item"> and add your focus style: the component ships none.
  • 60 px rows: a label that runs to three lines spills out of its tile (measured: 84 px of text for 58 usable px). Keep labels short or replace the fixed height with minmax(60px, auto).
  • Nothing moves: no animation, hence no special handling for reduced motion. White text at weight 600 on a near-black background.

Browser compatibility

CSS grid and container queries, no JavaScript. The three engines tested (Chromium 149, Firefox 151, WebKit 26.5) give the same switches — one column at 219 px, two at 220, three at 300 — and the same 220 px height; at 390 px wide on a phone, the three-column mosaic fits with no horizontal scrolling.

Chrome 105+✓ Full (measured in Chromium 149)
Firefox 110+✓ Full (measured in Firefox 151)
Safari 16+✓ Measured in WebKit 26.5; real Safari not verified
Edge 105+✓ Not verified (same engine as Chrome)
Mobile iOS 16+✓ Not verified on a device
Android Chrome 105+✓ Measured in 390 px emulation: three columns

Without @container, tiles stay in a single column at every width. Everything is there, but the stack is tall: 424 px for six tiles.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0754-root">
  <div class="grm-grid">
    <div class="grm-item">Featured tile <span class="grm-span">detail shown at 3 columns</span></div>
    <div class="grm-item">Tile</div>
    <div class="grm-item">Tile</div>
    <div class="grm-item">Tile</div>
    <div class="grm-item">Tile</div>
    <div class="grm-item">Tile</div>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Thresholds (CSS — @container grm (min-width: 220px) and (min-width: 300px)) 220 and 300 px Go up to 320 and 480 px for wider tiles; a fourth column needs one more rule.
Featured tile (CSS — .grm-item:first-child in the 300 px rule) span 2 across columns and rows grid-column: span 3 alone turns it into a full-width band; delete the rule for six equal tiles.
Row height (CSS — grid-auto-rows) 60 px 40 px for a dense list, minmax(60px, auto) to let tiles grow with long text.
First tile detail (HTML — <span class="grm-span">) Hidden under 300 px Put there what only belongs in the big tile: a value, a precision.
Tints (CSS — six :nth-child(6n+…) rules) Six colours at 15 % opacity Replace them with a single .grm-item { background: … } rule for a plain mosaic.
Spacing (CSS — gap, padding of .grm-grid) 8 px and 12 px Set padding to 0 if the grid already sits inside a card.

FAQ

Fluid Grid Morph keeps six tiles of the same size and relies on a script to slide them from their old cell to the new one. Grid Morph does not slide and has no script: its feature is the first tile, which takes four cells at three columns. Its thresholds are also lower (220 and 300 px against 280 and 440).
At three columns the big tile counts for four. With 6, 9 or 12 tiles the last row is complete; with 5, one empty cell is left at the bottom right, with 7, two. At two columns, aim for an even number.
Yes: the rules target the class, not the tag. On a link, add text-decoration: none; on a button, font-family: inherit and cursor: pointer; in both cases a :focus-visible style, which the component does not include.