Adaptive UI
A whole interface mockup (top bar, logo, theme button, wireframe lines and blocks) that goes from dark to light piece by piece in 0.5 s, without a single element changing place. One class set by 0.4 KB of JavaScript, the rest in CSS.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Transitions has 52 effects, including 9 free. Explore the category →
3 usage examples



How it works
The .aui-panel panel (280 px, 16 px corners) draws a small application: an .aui-nav bar with a text logo, three decorative dots and a 24 px round button, then a wireframe .aui-body, three lines 8 px high (80, 60 and 70% of the width) and a row of two 40 px blocks. That body holds no text: it stands for a screen, and it is hidden from screen readers. Keep it as a mockup or put your real content in it.
A click on the button adds the .aui-on class to the panel, a second one removes it. Twelve elements then change color together, each through its own rule: panel background and border, the rule under the bar, logo, dots, button badge, lines, blocks. The browser runs 24 transitions side by side (same count in Chromium, Firefox and WebKit). In dark mode the blocks already carry a transparent 1 px border, which takes its color in light mode: they measure 121 × 40 px before and after, nothing shifts. Only the icon swaps at once, sun in dark, moon in light.
One detail to know before adding text: the logo goes from white to midnight blue while its background travels the other way, and the two cross on the same grey. At 150 ms the contrast between logo and panel drops to 1.08:1; it stays under 3:1 from 110 to 190 ms, in both directions and in all three engines. On one word, the eye sees a fade. On a table, the figures go out for an instant: the Customize section gives the line that avoids it. And since these are transitions, two clicks 120 ms apart glide back to dark from the colors reached.
Accessibility
- Button: a native
<button>named "Light interface theme", whosearia-pressedturnstruewhen light is shown. Tab reaches it, Enter and Space toggle it, focus stays on it; 2 px purple outline, offset by 2 px. - By finger: the target is 24 × 24 px, the minimum of WCAG 2.2 criterion 2.5.8, far from a comfortable 44 px. On a touch screen, enlarge it (see Customize); emulated touch toggles it in all three engines.
- Reduced motion: nothing moves anyway; durations fall from 500 to 150 ms. The background is halfway 60 ms after the click and at its final color before 320 ms.
- Screen readers:
.aui-bodycarriesaria-hidden="true"because a wireframe has nothing to say. Remove the attribute as soon as you put real content there, or it will never be read. - Contrast at rest: logo at 17.9:1 in both themes; sun icon at 8.6:1, moon icon at 4.1:1 on their badge (the threshold is 3:1 for a pictogram).
Browser compatibility
CSS (color transitions, flexbox with gap) + 0.4 KB of JavaScript (closest(), classList.toggle), no dependency and no CSS variable. Toggle, U-turn midway, two copies on the same page, keyboard, emulated touch and reduced motion recorded in Chromium 149, Firefox 151 and WebKit 26.5: same final colors, same contrast dip at 150 ms. The floor comes from gap in flexbox: Chrome 84, Firefox 63, Safari 14.1. Below that, lines and blocks stick together but the toggle works. Before Chrome 86, Firefox 85 and Safari 15.4 (:focus-visible), the focus outline is the browser's own.
Without JavaScript, the interface stays dark and its button does not respond. To serve it light without script, write aui-on on .aui-panel in the HTML.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="aui-root">
<div class="aui-scene">
<div class="aui-panel">
<div class="aui-nav">
<span class="aui-logo">…</span>
<div class="aui-nav-dots" aria-hidden="true">
<span class="aui-nav-dot"></span>
<span class="aui-nav-dot"></span>
<span class="aui-nav-dot"></span>
</div>
<button class="aui-toggle" type="button" aria-pressed="false" aria-label="…">
<svg class="aui-sun" aria-hidden="true">…</svg>
<svg class="aui-moon" aria-hidden="true">…</svg>
</button>
</div>
<div class="aui-body" aria-hidden="true">
<div class="aui-line"></div>
<div class="aui-line"></div>
<div class="aui-line"></div>
<div class="aui-row">
<div class="aui-block"></div>
<div class="aui-block"></div>
</div>
</div>
</div>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Readable text during the switch (CSS — transition of .aui-logo and of your texts) |
color .5s |
With color 0s .15s, the text changes at once at 150 ms, when the background is at mid grey: contrast no longer goes below 3.5:1 instead of 1.08:1 (measured). Shortening the duration is not enough: at .2s, the text still crosses its background. |
Light colors (CSS — .aui-panel.aui-on … rules) |
panel #fff, logo #0f172a, lines #f1f5f9, blocks #f8fafc with a #e2e8f0 border |
Seven color rules, one per family of pieces. The light lines are very pale on white, on purpose for a wireframe; darken them toward #e2e8f0 if the mockup must read from afar. |
Button size (CSS — .aui-toggle { width; height } and its svg) |
24 px, 14 px icon | 34 px and an 18 px icon on a tablet; 44 px if the button is a main finger control. |
Panel width (CSS — .aui-panel { width }) |
280 px | Lines are percentages and blocks share the row: the panel holds from 100 px (thumbnail) to full width. At 100 px, remove the three dots to leave room for the logo. |
Wireframe (HTML — .aui-line, .aui-row, .aui-block) |
3 lines, 1 row of 2 blocks | Add rows and blocks freely. A line's place in its parent sets its width (1st: 80%, 2nd: 60%, 3rd: 70%); from the 4th place on, it takes the full width. |
Starting state (HTML — aui-on class on .aui-panel) |
absent: dark theme | To open in light, also write aria-pressed="true" on the button: the script only updates the attribute from the first click on. |
FAQ
transition: color 0s .15s on the texts: they change at once at the crossing point, and contrast no longer goes under 3.5:1.aui-on class: on reload, the interface is dark again, and the code does not read the system's light or dark setting. To keep it, save the choice in localStorage on click, then on load, in a script placed right after the interface, set aui-on on the panel and aria-pressed="true" on the button. The effect's script carries on from that state: this is how three of the four thumbnails in the third example start.