Keep app widgets above the bottom bar
Place a floating app widget, such as a chat bubble or WhatsApp button, above the theme's mobile bottom bar with the CSS variable --twilight-bottom-inset.
Use this when your store app or snippet adds a button fixed to the bottom of the screen: a chat bubble, a WhatsApp button, a "back to top" arrow, a cookie bar.
Goal: on a phone, your widget sits just above the theme's bottom navigation bar instead of covering its tabs. On desktop, and on themes without a bar, it stays where you put it.
React themes that have a fixed bottom bar on phones register it with useBottomInset. While the bar is visible, the engine sets this CSS variable on <html>:
--twilight-bottom-inset: 64px; /* the height the bar takes, in pixels */It is not set when the bar is hidden (desktop, or a bar that slides away), and not set on themes without a bar. The engine never moves your widget for you: you read the variable.
Add the variable to your widget's bottom
Keep the offset you already use, and add the variable to it. The 0px fallback keeps the widget where it was wherever the variable is not set.
.my-chat-launcher {
position: fixed;
inset-inline-end: 16px;
bottom: calc(var(--twilight-bottom-inset, 0px) + 16px);
}A widget that uses inset-block-end works the same way: inset-block-end: calc(var(--twilight-bottom-inset, 0px) + 16px).
Or set it from JavaScript
If your widget positions itself in script, or is added by a third-party loader whose CSS you cannot edit, set the same value as an inline style. Custom properties are inherited, so var() works on any element in the page:
const launcher = document.querySelector('#my-chat-launcher');
launcher.style.bottom = 'calc(var(--twilight-bottom-inset, 0px) + 16px)';The browser updates the position on its own when the variable changes, so there is nothing to listen for. To read the number itself, for example to size a panel, read it from <html>:
const inset = parseFloat(
getComputedStyle(document.documentElement).getPropertyValue('--twilight-bottom-inset')
) || 0;Animate the move (optional)
The bar can hide and show while the customer scrolls. A transition on bottom makes the widget follow smoothly:
.my-chat-launcher {
transition: bottom 200ms ease;
}Check it worked
Open the store at phone width (DevTools device mode) on a React theme with a bottom bar.
- In the console,
getComputedStyle(document.documentElement).getPropertyValue('--twilight-bottom-inset')returns a value such as64px. - Your widget sits 16px above the bar, and every tab of the bar can be tapped.
- Widen the window past the phone breakpoint: the bar hides, the variable is empty, and your widget drops back to 16px from the bottom.
Traps
- Always give a fallback.
var(--twilight-bottom-inset)without, 0pxmakes the wholecalc()invalid where the variable is not set, and the widget loses itsbottom. - Use
bottom, nottransform. Atransformon an element that contains other fixed elements becomes their containing block and moves them somewhere else. Many chat loaders nest a fixed iframe inside a fixed wrapper. - Put it on the element that is fixed. Setting
bottomon a wrapper with no size, or on a parent that is notposition: fixed, moves nothing. - Leave full-screen panels alone. An opened chat window that covers the screen should keep
bottom: 0. Add the variable to the launcher only. - Classic (Twig) themes do not set the variable. The fallback keeps your widget correct there.
Where to go next
- useBottomInset, for what the variable holds and when it changes.
- Run app code on a page, for widgets that only belong on some pages.