Motion
Motion is CSS-first, token-driven and close to platform behavior: short fades, a drawer that slides from its edge, popovers and menus that grow a little as they appear, and color changes on buttons, links and the switch. Nothing waits on a transition to work.
- Transitions only, no keyframe animations. Every component uses
transition. Dialogs, drawers and popovers animate in and out of the top layer with@starting-styleandtransition-behavior: allow-discrete(CSS Transitions 2). An engine without them opens and closes the element with no transition. - Tokens drive every duration and easing.
--dui-motion-duration-fast,-normaland-sloware primitives times--dui-motion-scale(default1), so one value on:rootmakes all motion slower (2) or off (0). Easings:--dui-motion-easing-standardfor state changes,--dui-motion-easing-enterfor things arriving,--dui-motion-easing-exitfor things leaving, and--dui-motion-easing-springfor popover, menu and drawer entrances: a critically damped spring written withlinear(), set only inside@supports, so an engine withoutlinear()keeps the enter curve. - Movement is a separate knob.
--dui-motion-movementis1by default. Distances (--dui-motion-distance,--dui-motion-zoom,--dui-motion-press-scale, the drawer's off-screen offset) and the duration of everytranslateorscaletransition are multiplied by it. - Reduced motion keeps fades and drops movement. Under
prefers-reduced-motion: reduce(Media Queries 5) movement becomes0: the drawer fades in place, popovers fade without growing, the switch thumb jumps while its color still fades. This is what 2.3.3 Animation from Interactions asks for. It says that motion animation triggered by interaction can be disabled. Our choice: keep opacity and color transitions under reduced motion, because a fade is not motion animation and it still shows where a change came from. data-motionon any element.data-motion="reduced"behaves exactly like the media query for everything inside.data-motion="none"sets--dui-motion-enabledto0, so every duration is0seven where a--dui-motion-scaleis set inside it. An emptydata-motionis a scope for your own--dui-motion-*overrides: motion tokens are re-declared on it, as theme tokens are on[data-theme](CSS Variables). Our choice: nodata-motion="full", so a page can never override a user's reduced-motion setting.- Essential feedback never animates. Focus indicators, validation errors and
aria-invalid, alert and live-region text, and loading state (aria-busy) change at once. Our choice: text fields do not animate their border at all, because the same border shows the invalid state. - View transitions are progressive enhancement only. domestic-ui starts none and nothing depends on
one. When your script calls
document.startViewTransition()(View Transition API, CSS View Transitions), the base layer gives its pseudo-elements the motion tokens inside@supports, so they follow the scale and reduced motion too.
| Transition | Components | Duration | Moves |
|---|---|---|---|
| Fade and lift | Dialog, toast | --dui-motion-duration-normal | translate by --dui-motion-distance |
| Slide and fade | Drawer | --dui-motion-duration-slow, spring | translate by 100% of its width |
| Scale and fade | Popover, menu | --dui-motion-duration-fast, spring | scale from --dui-motion-zoom |
| Color | Buttons, links, switch track | --dui-motion-duration-fast | No |
| Press | Buttons (:active) | --dui-motion-duration-fast | scale to --dui-motion-press-scale (0.98) |
| Thumb slide | Switch | --dui-motion-duration-fast | translate |
Our choice: 120, 200 and 300ms, longer for larger surfaces, with a decelerating (or spring) enter and an
accelerating exit, because short transitions keep the UI responsive and the curves match how things
arrive and leave. examples/motion.html shows each transition, the scale, and reduced
and no-motion scopes side by side.
Page transitions (opt-in)
css/domestic.css does not turn on page transitions. A site that wants them adds the
"Page transitions CSS" snippet below to its own stylesheet:
@view-transition { navigation: auto }
makes same-origin navigations cross-fade (CSS View Transitions Level 2),
a unique view-transition-name keeps persistent chrome such as the header in place, and the motion tokens set the
duration and easing, so data-motion="none" on the root element makes it instant. Under
prefers-reduced-motion: reduce it is off (2.3.3 Animation from Interactions).
Browsers without support navigate as before, with no script. These docs use it: the app bar and the Docs
sidebar stay while main cross-fades. Smashing Magazine lists it among
front-end features for designers, for comparison.
Live example
Fade: dialog
<button type="button" commandfor="fade-dialog" command="show-modal">Open dialog</button>
<dialog id="fade-dialog" data-dialog aria-labelledby="fade-dialog-title">
<header>
<h2 id="fade-dialog-title">Fade in, fade out</h2>
</header>
<p>Enters with <code>--dui-motion-easing-enter</code> and leaves with <code>--dui-motion-easing-exit</code>.</p>
<form method="dialog">
<footer>
<button type="submit" autofocus>Close</button>
</footer>
</form>
</dialog>
Page transitions CSS
In the <head> of the live example above.
<style id="page-transitions">
/* Opt in on every page of your site: same-origin navigations cross-fade. */
@view-transition {
navigation: auto;
}
@media (prefers-reduced-motion: reduce) {
@view-transition {
navigation: none;
}
}
/* Chrome that stays put while the content cross-fades: one unique name each. */
body > header {
view-transition-name: page-header;
}
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation-duration: var(--dui-motion-duration-normal);
animation-timing-function: var(--dui-motion-easing-standard);
}
</style>
Slide: drawer
<button type="button" commandfor="slide-drawer" command="show-modal">Open drawer</button>
<dialog id="slide-drawer" data-dialog="drawer end" closedby="any" aria-labelledby="slide-drawer-title">
<header>
<h2 id="slide-drawer-title">Drawer</h2>
<button type="button" commandfor="slide-drawer" command="close" data-button="quiet small">Close</button>
</header>
<p>The off-screen offset is 100% times <code>--dui-motion-movement</code>.</p>
</dialog>
Scale: popover and menu
<div class="cluster">
<button type="button" popovertarget="scale-popover">Popover</button>
<div id="scale-popover" popover data-popover>
<p>Grows and fades in.</p>
</div>
<dui-menu>
<button type="button" popovertarget="scale-menu">Menu</button>
<div id="scale-menu" popover data-popover>
<button type="button">Rename</button>
<button type="button">Duplicate</button>
</div>
</dui-menu>
</div>
Color and state
<div class="cluster">
<button type="button">Hover me</button>
<button type="button" data-button="primary">Primary</button>
<a href="#state-title">A link</a>
<label><input type="checkbox" role="switch" name="state-switch"> Switch</label>
</div>
Toast
<button type="button" data-toast="success">Save</button>
<dui-toaster role="status"></dui-toaster>
Motion scale
<div class="panel cluster" data-motion style="--dui-motion-scale: 3">
<button type="button">Hover me</button>
<label><input type="checkbox" role="switch" name="slow-switch"> Slow switch</label>
<button type="button" popovertarget="slow-popover">Slow popover</button>
<div id="slow-popover" popover data-popover>
<p>Three times the normal duration.</p>
</div>
</div>
Reduced and no motion
<div class="grid">
<section class="panel stack" data-motion="reduced" aria-labelledby="reduced-title">
<h3 id="reduced-title">data-motion="reduced"</h3>
<label><input type="checkbox" role="switch" name="reduced-switch"> Switch</label>
<div class="cluster">
<button type="button" popovertarget="reduced-popover">Popover</button>
<div id="reduced-popover" popover data-popover>
<p>Fades without growing.</p>
</div>
<button type="button" commandfor="reduced-drawer" command="show-modal">Drawer</button>
</div>
<dialog id="reduced-drawer" data-dialog="drawer end" closedby="any" aria-labelledby="reduced-drawer-title">
<header>
<h2 id="reduced-drawer-title">Reduced motion</h2>
<button type="button" commandfor="reduced-drawer" command="close" data-button="quiet small">Close</button>
</header>
<p>Fades in place instead of sliding.</p>
</dialog>
</section>
<section class="panel stack" data-motion="none" aria-labelledby="none-title">
<h3 id="none-title">data-motion="none"</h3>
<label><input type="checkbox" role="switch" name="none-switch"> Switch</label>
<div class="cluster">
<button type="button" popovertarget="none-popover">Popover</button>
<div id="none-popover" popover data-popover>
<p>Appears at once.</p>
</div>
<button type="button" commandfor="none-drawer" command="show-modal">Drawer</button>
</div>
<dialog id="none-drawer" data-dialog="drawer end" closedby="any" aria-labelledby="none-drawer-title">
<header>
<h2 id="none-drawer-title">No motion</h2>
<button type="button" commandfor="none-drawer" command="close" data-button="quiet small">Close</button>
</header>
<p>Appears at once.</p>
</dialog>
</section>
</div>
View transition
<div class="stack">
<ol id="vt-list" class="stack" style="--stack-gap: var(--dui-space-2xs)">
<li>Draft</li>
<li>Review</li>
<li>Publish</li>
</ol>
<p><button type="button" data-reverse="vt-list">Reverse the list</button></p>
</div>