TransitionsPremium

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.

CSSJSUIAdaptive

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

Weighing grape bins in full sun — dock tablet of a wine cooperative during harvest — Adaptive UI example 1

① Weighing grape bins in full sun — dock tablet of a wine cooperative during harvest

WhenMid-afternoon on the receiving dock: the sun beats down on the tablet and the dark theme can no longer be read. The weighing agent taps the round button in the bar; in half a second the whole screen turns black on white, from the three counters at the top down to the bin being weighed.
WhyNothing moves during the change: the time, grower, grape and weight columns keep their place, the eye does not lose the row it was reading.
Settings.aui-panel stretched to 540 × 360 px, no rounding; button raised to 34 px for the finger. The three .aui-block elements get a figure and its caption, and the weighing rows are added in .aui-body following the effect's recipe: a dark color, a light color under .aui-panel.aui-on, a 0.5 s transition. In the capture, the scene presses the real button by itself, then a second time to return to dark.
Software mockup to view in dark — hero of a quoting tool for landscapers — Adaptive UI example 2

② Software mockup to view in dark — hero of a quoting tool for landscapers

WhenA landscaper discovers Sarclène. To the right of the headline, a wireframe mockup of the software; he clicks its round button to see whether the tool also exists in light, the version he will use outdoors, at his clients' homes.
WhyThe mockup answers a buying question with no screenshot to redo: it shows no real screen, so it does not go stale with each new release of the software.
Settings236 px .aui-panel with a drop shadow, logo replaced by the product name. The body keeps the original wireframe and extends it: three lines, a row of two 46 px blocks, a row of three 30 px blocks, one last line. In the capture, the scene presses the real button by itself, there and back.
Dark theme review, screen by screen — QA board of an app studio — Adaptive UI example 3

③ Dark theme review, screen by screen — QA board of an app studio

WhenBefore release 3.2 ships, the designer reviews the app's four screens. Each thumbnail has its button: she switches "Search" to dark, looks at the rules and greys, then does the same with "Listing". Under each thumbnail, the chip goes from "to check" to "dark: checked".
WhyThe four thumbnails are four independent copies: a screen already switched to dark sits side by side with a screen left in light.
SettingsFour 99 px wide .aui-panel elements in a grid, without the three dots, with a different wireframe per screen. Three start in light: aui-on on the panel and aria-pressed="true" on the button, written in the HTML. The status chip belongs to the scene: it watches the panel's class. In the capture, the scene presses the real buttons of two thumbnails by itself.

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", whose aria-pressed turns true when 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-body carries aria-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.

Chrome 84+✓ Full (measured in Chromium 149)
Firefox 63+✓ Full (measured in Firefox 151)
Safari 14.1+✓ Full (measured in WebKit 26.5)
Edge 84+✓ Full (Chromium engine)
Mobile iOS 14.5+✓ Not checked on a device
Android Chrome 84+✓ Full (emulated touch)

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):

index.html — structure
<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 / propertyDefaultEffect
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

The mechanics are the same: a button sets a class, and each piece goes from its dark color to its light color in 0.5 s. The object is what changes. Card Theme is a profile card ready to fill: avatar, name, paragraph, two action buttons. Adaptive UI is an application mockup: a top bar with logo and theme button, then a wireframe body, with no text. Card Theme for a content component; Adaptive UI to show or test the theme of a whole app, or as the skeleton of a screen to fill.
Because the text and its background travel opposite ways at the same time and cross on the same grey. On the demo's logo, contrast drops to 1.08:1 at 150 ms and stays under 3:1 for 80 ms. On a heading, it passes for a fade; on a table of figures, you notice it. The cure is one line, transition: color 0s .15s on the texts: they change at once at the crossing point, and contrast no longer goes under 3.5:1.
No. The state only lives in the 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.