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…
Breakpoint observer for a header menu: shows your popover trigger and hides the desktop nav below a viewport width.
Overview
The <mobile-menu> element is a breakpoint observer. At or below a configurable viewport width it shows its contents and hides sibling <nav>, <nav-bar> and <site-tools> elements in the parent <header>. Above the breakpoint it hides itself.
It generates nothing. You write the trigger button and the menu panel inside it. The panel is a native HTML popover, so opening, closing, Esc and the backdrop work without any script from this element.
Viewport width at or below which mobile mode activates. Observed: changing it re-evaluates immediately.
data-mobile
boolean (state)
—
Set by the element while mobile mode is active. Style against it; do not set it yourself.
Basic Usage
Place <mobile-menu> as a direct child of a <header>, alongside the desktop navigation. Put both the trigger and the panel inside it: the link, section and current-page styles are scoped to mobile-menu. The trigger needs data-trigger and a popovertarget that names the panel's id. Give the panel an aria-label so its navigation landmark has a name.
Header with mobile menu
<headerclass="site"data-sticky=""><ahref="/"><brand-mark>Acme Inc</brand-mark></a><navclass="horizontal pills"aria-label="Main navigation"><ul><li><ahref="/about">About</a></li><li><aclass="active-parent"href="/docs">Docs</a></li><li><ahref="/blog">Blog</a></li></ul></nav><site-tools><site-search><buttontype="button"data-trigger=""class="ghost">Search</button></site-search></site-tools><mobile-menubreakpoint="52rem"><buttontype="button"data-trigger=""popovertarget="main-menu"aria-label="Menu"><icon-wcname="menu"></icon-wc></button><!-- Panel lives inside mobile-menu so its styles apply --><navpopover=""id="main-menu"class="mobile-menu-panel"aria-label="Site menu"><buttontype="button"class="mobile-menu-close"popovertarget="main-menu"popovertargetaction="hide"aria-label="Close menu"><icon-wcname="x"></icon-wc></button><ul><li><ahref="/about">About</a></li><li><aclass="active-parent"href="/docs"aria-current="page">Docs</a></li><li><ahref="/blog">Blog</a></li></ul></nav></mobile-menu></header>
For automatic aria-current in the panel, wrap its list in a <nav-bar> inside the popover <nav>.
CSS Tokens
Theme the panel appearance with these custom properties:
Token
Default
Description
--mobile-menu-bg
var(--color-surface)
Panel background
--mobile-menu-radius
var(--radius-m)
Panel border radius
--mobile-menu-shadow
Subtle shadow
Panel box shadow
--mobile-menu-padding
var(--size-l)
Panel padding
--mobile-menu-max-width
280px
Panel maximum width
--mobile-menu-backdrop
Semi-transparent black
Backdrop overlay color
How It Works
On connect, and whenever breakpoint changes, the element creates a matchMedia('(max-width: …)') observer. The breakpoint is the viewport width, not a container width, because the menu replaces page-level chrome.
When the viewport crosses the breakpoint, it sets or removes [data-mobile] on itself.
CSS does the rest: header:has(> mobile-menu[data-mobile]) > :is(nav, nav-bar, site-tools) is hidden. No inline styles are written, so removing the element (or leaving mobile mode) always restores the desktop chrome.
When switching back to desktop, it closes the panel if it is open.
Moving a header tool into the menu
Search and a theme picker can simply be repeated inside the panel. A tool that should exist once, such as a notification bell, is marked data-mobile-menu in the header instead. In mobile mode the element moves that sibling into the panel, appending it to the element marked data-mobile-menu-slot (or to the end of the panel when there is no slot), and puts it back in its place in the header on leaving mobile mode or when the menu is removed. It is the same element throughout, so its state and listeners carry over. Before upgrade, and without JavaScript, the marked sibling is hidden at the default breakpoint along with the rest of the desktop chrome.
If the moved tool carries data-unread (<notification-wc> sets it while there are unread items), the menu button shows a dot, since the tool itself is out of sight until the menu opens.
The default 52rem breakpoint is also a CSS media query, so the right state paints before the element upgrades (no layout shift) and even without JavaScript. Because popover and popovertarget are native, the menu still opens and closes with JavaScript off. A custom breakpoint needs JavaScript; without it, the desktop nav stays visible at every width.
Accessibility
The trigger button should have aria-label="Menu" for screen readers. popovertarget gives it aria-expanded automatically.
Label the panel (aria-label="Site menu"). An unnamed <nav> is a second, anonymous navigation landmark.
The native popover gives you Esc to close, light dismiss on an outside click, and focus back on the trigger when it closes. It is not modal: there is no focus trap, the rest of the page stays reachable, and the page still scrolls. Focus does not move into the panel when it opens; the panel's links come next in the tab order after the trigger. If you need a modal menu, use a <dialog> opened with showModal() instead.
Include a close button inside the panel with popovertargetaction="hide".
The current-page link uses --color-text-on-interactive-auto on the interactive colour. In forced-colors mode it also gets an outline and underline.