0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Two-face content toggle with flip, fade, slide, and scale transitions. Theme-driven motion via design tokens.
Overview
The <content-swap> component toggles between two content faces with configurable transition effects. It manages inert on the hidden face so screen readers only announce visible content.
The transition type is a styling concern (transition), while duration and easing come from VB motion tokens — so themes automatically control the personality of every swap.
Basic content swap (flip)
12345678
<content-swaptransition="flip"><divdata-face="front"><p>Front content visible by default.</p></div><divdata-face="back"><p>Back content revealed on swap.</p></div></content-swap>
Marks an element as a swap trigger. Use a <button type="button">.
data-swap-toggle
Direct child
Toggle button used when there are no data-swap triggers. Generated (text “Show back”) if absent; author your own <button type="button" data-swap-toggle> to set or localize the label. Kept in sync via aria-pressed.
Transition Effects
Each transition reads from VB motion tokens, so themes automatically control personality.
By default (no data-swap triggers), clicking the surface swaps for pointer users, and a generated <button data-swap-toggle> — visually hidden until it receives keyboard focus — is the keyboard and screen-reader control. Clicks on links, buttons and form fields inside a face keep their own behavior.
Add data-swap to specific buttons for explicit, always-visible trigger controls. When triggers exist, the surface is no longer clickable and no toggle is generated.
Trigger buttons
12345678910
<content-swaptransition="fade"><divdata-face="front"><p>What does inert do?</p><buttondata-swap>Show answer</button></div><divdata-face="back"><p>It makes an element non-interactive.</p><buttondata-swap>Back to question</button></div></content-swap>
Card Mode
Add card to apply layout-card's visual shell directly on the swap element. Supports data-variant for elevated, outlined, and ghost styles.
Card mode shorthand
12345678910
<content-swaptransition="flip"card><divdata-face="front"><h3>Product</h3><p>Flip to see details.</p></div><divdata-face="back"><h3>Details</h3><p>Price, specs, and more.</p></div></content-swap>
Page-level auto-card
Add data-swap-autocard to a container or <body> to automatically apply card chrome to all content-swap elements that don't already wrap <layout-card> children.
Auto-card opt-in
123456
<bodydata-swap-autocard><content-swaptransition="slide-left"><divdata-face="front">Auto-styled as card</div><divdata-face="back">Auto-styled as card</div></content-swap></body>
Composition
Wrap <layout-card> elements as faces for full card structure (header, section, footer) on each side.
The composition example is the third card in the Card Mode demo above.
Composition with layout-card
123456789101112
<content-swaptransition="flip"><layout-carddata-face="front"><header><h3>Front</h3></header><section><p>Full card structure per face.</p></section><footer><buttondata-swap>See back</button></footer></layout-card><layout-carddata-face="back"><header><h3>Back</h3></header><section><p>Each face is a layout-card.</p></section><footer><buttondata-swap>See front</button></footer></layout-card></content-swap>
Attribute Form
For authors who want swap behavior on an existing element, add data-swap as an attribute on any element with data-face children. The behavior auto-initializes via JavaScript (the host gets data-swap-init once upgraded). Use data-transition and data-swapped in place of transition and swapped. The second example in the Trigger Buttons demo uses this form.
Fired after the content swaps. source says what caused it: a click or swipe, a keyboard activation, or a method/property call.
Listening to swap events
12345
const el = document.querySelector('content-swap');el.addEventListener('content-swap:swap', (event) => {console.log('Swapped:', event.detail.swapped, 'via', event.detail.source);});
JavaScript API
Method / Property
Description
flip()
Swap to show the back face.
unflip()
Swap to show the front face.
toggle()
Toggle between front and back.
swapped
Boolean property reflecting the current state.
flipped
Alias for swapped (backward compatibility).
Programmatic control
12345678910111213
const el = document.querySelector('content-swap');// Swap to back faceel.flip();// Swap to front faceel.unflip();// Toggle current stateel.toggle();// Check stateconsole.log(el.swapped); // true or false
Theme Integration
Content-swap reads from VB motion tokens. Themes override these tokens, so personality comes for free:
No extra theme CSS needed — the token bridge handles it.
Accessibility
Inert Toggling
The hidden face is always marked inert. Screen readers only announce the currently visible face, and interactive elements on the hidden face cannot receive focus.
Trigger Modes
Whole-element mode (no data-swap children): the container is never turned into a button, so headings, links and other face content stay individually reachable. A real <button type="button" data-swap-toggle aria-pressed> is appended outside both faces (so it is never made inert); it is visually hidden until focused, then shown over the corner of the card. Surface clicks are a pointer convenience only.
Explicit triggers (data-swap children): the trigger buttons are the keyboard targets. Nothing is added to the container. Use <button type="button">; a trigger that is not a button or link is given role="button" and tabindex="0" (unless it already has them) and responds to Enter and Space.
Focus Management
An element with autofocus on the incoming face is always focused. Otherwise focus only moves on keyboard swaps whose focus was inside the outgoing face (for example a data-swap trigger that is about to become inert): it goes to the first trigger, button, link or field on the incoming face. Pointer and API swaps leave focus alone, and the generated toggle keeps focus because it sits outside both faces.
Reduced Motion
When prefers-reduced-motion: reduce is active, the swap animation duration is set to 0s. The state still toggles instantly without animation.
Progressive Enhancement
Without JavaScript, both faces display stacked in natural document flow. Stacking into one grid cell and the transition transforms only apply once upgraded (content-swap:defined or [data-swap][data-swap-init]), and the first upgrade settles without animating.
Related
<layout-card> — Card visual shell (compose with content-swap)