Glass and motion
A brand-neutral kit: brand-tinted frosted glass over a wallpaper, and calm, tuned motion. It is plain CSS plus a little plain JS, with no dependencies and no build step. It works on any stack that can load a stylesheet and a script.
Nothing in it belongs to one project:
- Every colour is a placeholder variable.
- The demo's content is generic.
- Layout sizes (bar heights, rail width, save-bar offsets) are variables or live in the demo.
The motion values came out of a production panel, where they were tuned by eye. Each project brings its own brand, fonts and layout.
Files
| File | What it holds |
|---|---|
glass-ui.css | Tokens, wallpaper, glass, press and hover, controls, page rise, dialogs, save pill, data motion, the opening, reduced-motion and reduced-transparency fallbacks |
glass-ui.js | window.GlassUI: swapLook (theme or wallpaper cross-fade), slideMarker, countUp, riseOnView and RISE_HEAD_SCRIPT, whenRisen, replay, playOpening and OPENING_HEAD_SCRIPT |
react.md | motion/react versions (layoutId marker, CountUp, live list, tour springs), the opening in Next.js, Tailwind v4 mapping |
demo.html | Every piece on one page (except the donut fade). Open it to see the target feel, and copy its markup |
contrast.mjs | The contrast check for a palette (node contrast.mjs) |
Fit it to the project
Pick the pieces by the kind of project. Don't put the full set everywhere.
| Project | Pieces |
|---|---|
| Landing page, corporate site, portfolio | wallpaper, a .glass sticky nav, press, card hover, link cards with arrow nudge, data-rise on the first screen, data-rise data-rise-view on each section below it, dialogs; maybe the opening on the home page only |
| Shop, booking, catalogue | the above plus .popover (filters, dates), a cart or filter <dialog> (a .sheet on phones), .value-in on totals, skeletons, .seg with the sliding marker for variants and tabs |
| Dashboard, panel, SaaS | the full set: .glass-sheet, a .glass-rail side nav or phone tab bar with the sliding marker, save pill, switches, count-up, chart motion, live feed, theme and wallpaper swap |
Sites without an app shell (the first two rows) have no page sheet: put data-no-sheet on <html>.
- Cards stay at 92%, and the pattern isn't faded under the header.
- A photo wallpaper keeps the firm veil at every width; without it, hero text fails contrast.
- A firm veil hides most of the photo, so on these sites the mark or pattern wallpaper usually shows more.
Any stack
- Plain HTML, WordPress, Shopify, Webflow, Squarespace custom code:
- Add
glass-ui.cssto the theme's stylesheet. - Load
glass-ui.jsin<head>and callGlassUI.riseOnView()there. - Put the classes in the templates.
- Add
- React, Next.js, Remix: see
react.md(motion/react versions, head scripts, Tailwind v4). - Vue, Nuxt, Svelte, SvelteKit, Astro, Angular:
- Import
glass-ui.cssonce, globally. - Put the head scripts in the app's HTML shell or head component.
- Call
slideMarker()/swapLook()/countUp()after render (onMounted,onMount, a client script). - The CSS animations need nothing from the framework.
- Import
- CSS Modules, scoped styles, CSS-in-JS: the kit's classes are global by design. Load the file as a global stylesheet, or wrap it in
:global(...), so hashing doesn't rename them. - Tailwind (any version): import the kit into the components layer, so utilities still win (
react.md). - Right-to-left sites (
dir="rtl"): the arrow nudge, switch knob and meters flip on their own.
Keep the project's own:
- fonts (the kit sets none);
- spacing;
- breakpoints, where they differ: the kit uses 48rem / 64rem, so change those media queries to match;
- radii (
--gm-radius-*); - bar heights (
--gm-top-bar,--gm-bottom-bar).
Apply it
-
Look first. Open
demo.htmlin a browser (default: the photo wallpaper; the play button replays the opening), so you know the result you are aiming for. -
Read the target project.
- Find out how it styles (plain CSS, Tailwind v4, CSS modules) and whether it already uses React with
motion. - Check every class the kit defines against the project. List them with
grep -oE '^\.[a-z][a-z-]*' glass-ui.css | sort -u, then grep the project for each one, CSS libraries included (Bootstrap has.btnand.card). Rename the kit's class where one clashes. - Common clashes:
.opening(the kit hides it),.card,.btn,.field,.reveal,.fade-in,.skeleton,.dragging,.sheet,.popover,.spin. - Global rules to know about:
- the reduced-motion
*rule cuts every animation on the site, the host's own included; - modal
<dialog>s underdata-gmpop in with a scrim, at zero specificity, so the host's own dialog classes win.
- the reduced-motion
- Find out how it styles (plain CSS, Tailwind v4, CSS modules) and whether it already uses React with
-
Copy
glass-ui.cssinto the project. Copy only the sections the site needs (see "Which pieces" below), and keep the comments that explain why. With Tailwind, import it into the components layer (react.md). -
Map the palette to the brand. Every brand value, in one pass:
- the two palette blocks
[data-gm="light"]and[data-gm="dark"], including--gm-pattern(one pre-tinted tile per theme, made from the brand's mark); - the desktop surface (84% / 82%, only under a sheet) in the
@mediablock right after them; - in
:root:--gm-rail(RGB triplet),--gm-curtain,--gm-curtain-text,--gm-curtain-muted,--gm-scrim, and the radii; .wall-photo'ssepia(0.5), which warms the photo; drop it for a cool brand;.glass-rail's remapped text and selection colours;.save-pill's glass in both themes.
Rules:
- The glass is tinted with the brand's page colour. It is not white, unless white is the brand.
--gm-shade, the shadows and the scrim use the brand's darkest colour. Never pure black.- One accent colour does all the actions.
- "Hover" is a tint of the brand colour, not grey.
- A light theme can use the brand's dark colour as its accent. A dark theme can use the brand's light or bright colour.
Copy the same values into
contrast.mjs, set itssheetflag, delete the theme or rail the site doesn't have, and run it. - the two palette blocks
-
Never change the timing. Keep the durations, distances, stagger steps and curves as they are. They were tuned by eye, and the "why" lines below record what failed.
-
Add the markup contracts.
demo.htmlhas each of these.data-gmon<html>. Only there: any opaque wrapper between the wallpaper and the content hides the wallpaper.- A
.walllayer. data-riseon the page root, anddata-rise-groupon its top-level grid or form.data-risemoves its children, never itself, and the steps come from child order. Adata-risenested in another one takes the quicker tab-panel timing, unless it also hasdata-rise-view.- On long pages, also mark each section below the fold with
data-riseanddata-rise-view. CallGlassUI.riseOnView()in<head>, before the first paint: loadglass-ui.jsthere, or inlineRISE_HEAD_SCRIPT. Called later, the blocks have already risen unseen. - With a phone tab bar, put
data-tabbaron<html>and set--gm-bottom-bar. Set--gm-top-barto the header's height. .pressableon everything tappable..nudgeor.nudge-backon a link, with.nudge-iconon its arrow.- The
.save-dockmarkup. Set itsbottomandleftaround the page's bars. - For the opening:
- the
.openingmarkup; data-opening-targeton the page's own logo. If that logo sits on a coloured disc (its parent's background), a coin in that colour grows under it as it lands;OPENING_HEAD_SCRIPTinline in<head>, only on pages that have both of the above;GlassUI.playOpening()after load.
- the
For JS, include
glass-ui.js, or port the functions you need into the project's module. On React usereact.md.Patterns the markup doesn't cover:
- Count-ups and timers below the fold: start them with
GlassUI.whenRisen(block, fn). It runs at once when nothing waits (reduced motion, no JS rise). - Filtering a grid: re-shown cards take their steps from
nth-child, hidden ones included. Set--riseinline on the visible ones (0, 1, 2…), then replay them. - Popovers: the kit animates and frosts
.popover. The page positions and dismisses it; the nativepopoverattribute gives light dismiss. - A cart that is a sheet on phones and a modal on desktop: toggle
.sheetbeforeshowModal(), bymatchMedia("(max-width: 47.999rem)"). - What the kit leaves to the page: padding and radius on
.glassand.glass-railelements, the layout, and the type scale.
-
Run the check at the end of this file.
Which pieces
| Piece | Class or attribute | Values | Use on |
|---|---|---|---|
| Wallpaper | .wall with .wall-mark / .wall-pattern / .wall-photo + .wall-veil; choose one with data-wall | photo: blur 10px, sepia .5, scale 1.06; veil 50–62% (86–90% on phones) | anything with glass; glass over a flat colour is invisible |
| Glass | .glass (bars, pills) | 24px blur, saturate 1.3, 160° shine, 1px edge, glass 60–62% | sticky top bar, floating controls |
| Page sheet | .glass-sheet | 40px blur and 32px radius from 64rem; none on phones | the content column of an app |
| Brand rail | .glass-rail | --gm-rail at 90%, 24px blur, tokens remapped inside | side nav, phone tab bar, a brand-coloured sheet |
| Card | .card | surface 92% (84% from 64rem), 16px radius, hairline, low shadow | content blocks; never nested |
| Press | .pressable, .pressable-row | scale .97 (rows .985) in 90ms cubic-bezier(0.2,0,0,1); colours 160ms | every button, link row, tile |
| Card hover | .card-lift | −2px and deeper shadow, 450ms --ease-smooth, both ways, mouse only | dashboard tiles, chart cards |
| Link card | .card-link + .pressable | −1px, deeper shadow | a card that is one big link |
| Arrow nudge | .nudge / .nudge-back + .nudge-icon | 2px, 200ms | "See all →", "← Back" |
| Buttons | .btn .btn-primary/-secondary/-ghost/-danger + .pressable | 44px pills; pending: .spin icon + disabled | all actions |
| Field | .field (also on <textarea>) | 44px, 16px text, hairline firms on hover, firmer fill on focus (150ms) | inputs, selects, message boxes |
| Switch | .switch (role="switch") | knob 320ms --ease-spring, track 200ms | on/off settings |
| Segmented control | .seg with a .slide-marker inside | 44px pills, 16px labels; the chosen one takes aria-selected, aria-pressed or aria-current | tabs, filters, Monthly/Yearly, product variants |
| Focus ring | built in under data-gm | 2px accent outline, 2px offset, follows each element's radius | every control |
| Sliding marker | .slide-marker + slideMarker() (React: layoutId) | spring, response .32s, no bounce | active nav item, tabs, segmented control |
| Disclosure | .chevron, details[open] > .reveal, .rise-in | chevron turns 200ms; content rises 8px in 220ms (a nested detail row: 200ms) | accordions, expandable rows, a status line that changes |
| Page rise | data-rise, data-rise-group | 20px, 800ms --ease-smooth, 70ms apart, ≤6 steps, nested row left→right; tab panels 560ms / 50ms | every page; the first screen of a long page |
| Scroll rise | data-rise + data-rise-view, riseOnView() | the page rise, started when the block scrolls into view | sections below the fold |
| Dialog | any modal <dialog> under data-gm | rise 8px + scale .98 in 220ms; brand-tinted scrim + 2px blur; the page behind stops scrolling | modals, ⌘K palette |
| Popover | .popover | the dialog's pop in 180ms; 24px blur | date picker, dropdown menu |
| Bottom sheet | <dialog class="sheet"> | from the bottom edge, 360ms --ease-sheet | phone "More" menu, pickers |
| Save pill | .save-dock[data-open][data-done] > .save-pill.glass | up 380ms, down 240ms ease-in; "Saved." holds 2.75s, then sinks over 450ms | edit forms |
| Count-up | countUp() / CountUp | 900ms cubic ease-out | stat figures |
| Chart motion | .grow-y, .grow-x, .grow-x-live, .fade-in, .fade-in-slow | see below | charts, progress meters, top-N lists |
| Value change | .value-in | fade 200ms (an overlay on a tile: 160ms) | a preview figure that just changed |
| Live | .live-dot, .row-in | 2.4s ping; new row drops 10px in 320ms | live feeds |
| Skeleton, spinner | .skeleton, .spin | pulse 2s; spin 1s | loading |
| Theme swap | swapLook() | view-transition cross-fade | light/dark, wallpaper picker |
| Opening | .opening markup + OPENING_HEAD_SCRIPT + playOpening() | logo writes in 800ms → flies to the page logo 650ms → page opens in a circle 900ms; about 2.4s; any key or press skips | an app's entrance, once per session |
Chart motion values:
- Columns grow over 500ms, each starting
min(24, 250/n)ms after the previous one. - Meters fill over 700ms.
.grow-x-livetakes its value astransform: scaleX(v)on a full-width bar, so it also eases to a new value. - Value labels fade in over 300ms, after a 300ms delay.
- Donut segments fade in over 600ms, 90ms apart.
- Ranked rows use
.rise-inat 260ms, 40ms apart (at most 10 rows), and each row's meter starts 120ms after its row.
Why it is built this way
These are the lessons behind the values. Keep them.
Glass
- Blur goes on
::before, never on the element. Abackdrop-filtermakes the element the containing block of itsposition: fixedchildren, so a fixed save bar inside<main>would scroll away. For the same reason,.glasssets noposition: each element setsrelative,stickyorfixeditself. - Glass needs a wallpaper. Put a gradient, a big faint logo, a pre-tinted pattern or a blurred photo behind it. Over a flat colour, glass looks like a grey box.
- Text never sits on bare glass. Cards stay near-solid (92%, 84% on the sheet), so text holds 4.5:1 over every wallpaper. Phones have no sheet, so a photo wallpaper gets a firm veil (86–90%).
- Use pattern tiles, not a CSS mask. A repeating mask under glass left marks on text in Chrome. Use one pre-tinted tile image per theme.
Motion
- Card motion uses
--ease-smooth, both ways. A fast-start curve (--ease-out-soft) did most of a 2px lift in the first ~50ms and read as a snap. Small things that arrive (dialogs, rows, status text) keep--ease-out-soft. - The page rise is 20px over 800ms. A first try at 8px over 260ms went unnoticed.
- The rise rules have zero specificity (
:where). An element's own animation (a skeleton's pulse) wins, and so does the curtain's pause. - Hover is never a glow. Lights under the pointer were tried in five colours and all removed. A card only deepens its shadow and lifts at most 2px. Hover is for the mouse only (
@media (hover: hover)), so a tap never leaves anything lit. - Exits are faster than entries. For example, the save pill comes up in 380ms and goes down in 240ms ease-in.
- Use
animation-fill-mode: backwardsand animate only transform and opacity. Once done, no transform is left on a block, because a leftover transform also traps fixed children. Never animate layout properties (the marker's width is the one exception, kept small). - Run once on mount. A CSS animation on mount never replays on a re-render. A tab panel that comes back from
display: nonereplays on purpose. - Below the fold, wait for the scroll. Otherwise the rise plays where no one sees it. Only JS sets the waiting state, so without JS (or under reduced motion) nothing is ever left hidden. A block counts as seen when any pixel of it is on screen, so even a short footer at the very end rises. In print, nothing waits.
Reduced settings
- Reduced motion: one global rule cuts everything to 1ms, and hover lifts stay put. The "Saved." linger is the exception: it stays instead of vanishing, and infinite loops stop.
- Reduced transparency: the glass becomes the solid page colour, the rail becomes solid brand, and dialogs, popovers and the scrim lose their blur. Cards stay near-solid as they are.
The opening
- It plays once per browsing session, on a fresh navigation. It never plays on a reload, on Back, on the site's other pages, or under reduced motion.
- A single-page app that should greet every new visit can drop the head script's two
sessionStoragecalls. An app can also replay it after sign-in (react.md). - Any key or press ends it, because a work tool must not hold people hostage.
- The page's rise waits behind the curtain, so the cards come up inside the circle. Count-ups wait too: hold the figures at 0 under the curtain, then count as it opens (
demo.html). - Without view transitions, the curtain fades instead.
- With no visible target it gives up after 10s and fades. If the
.openingmarkup is missing, it clears at once.
Check (all must pass)
- Contrast. Run
node contrast.mjswith the brand's values. Every text step must be at least 4.5:1: on a card, on the page sheet and on the veil, over the worst photo pixel, in both themes, and on the rail. - Widths. Look at phone (390), tablet (820) and desktop (1440), in light and dark, in a background browser tab. Fixed bars stay fixed inside the glass sheet, and nothing scrolls sideways.
- Reduced motion. Emulate
prefers-reduced-motion: reduce. Nothing travels, "Saved." stays, the opening doesn't play. - Reduced transparency. Emulate
prefers-reduced-transparency: reduce. There is no blur anywhere. - Opening. While the curtain is up, the page's cards are paused at their start. They rise inside the circle.
- Scroll rise. A
data-rise-viewblock below the fold is paused (its chart motion too) until it scrolls in, then rises. The last block on the page rises at the end of the scroll. With JS off it shows on load.- In tests, scroll in steps: a jump skips the blocks in between.
- Take full-page screenshots after a scroll pass.
- Under reduced motion
data-risenis never set, because nothing waits.
- Focus. Tab through the page: every control shows the accent ring.
- Timing. Grep the project's copy for
ms,cubic-bezierandlinear(. Every value matchesglass-ui.css.