Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

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…

Read the release notes

data-visible

Responsive visibility utility. Show or hide elements by viewport width or by the width of their container, without writing custom media or container queries.

Overview

The data-visible attribute controls element visibility by width. desktop and mobile measure the viewport; wide and narrow measure the element's container. It eliminates the need for custom @media and @container queries for the common two-variant case.

  • data-visible="desktop" — visible at 48 rem and above, hidden below
  • data-visible="mobile" — visible below 48 rem, hidden at 48 rem and above
  • data-visible="wide" — visible when the nearest query container is 30 rem or wider, hidden when it is narrower
  • data-visible="narrow" — visible when the nearest query container is under 30 rem, hidden at 30 rem and above

The viewport breakpoint is --bp-m (48 rem, src/tokens/breakpoints.css), a typical tablet/desktop threshold. There are only these four values; for another breakpoint (a tablet tier at --bp-l, say) write your own @media or @container rule.

How It Works

For the viewport values, two media queries set display: none !important on the opposite breakpoint:

Works on any element — not just navigation. A hamburger button, a bottom nav, a sidebar, a CTA banner, or any content block can use data-visible.

It always wins

The rules sit in the lowest framework layer (reset, next to [hidden]) with !important. An important declaration in an earlier layer beats every normal declaration and every later layer's important ones, so a hidden variant stays hidden even on components that lock their own display (<content-swap>'s display: grid !important) and against your own unlayered display rules. To show the element, remove or change the attribute.

Viewport or container

desktop and mobile measure the viewport. Inside a narrow sidebar or card on a wide screen, mobile content stays hidden. When the element should respond to the space it has, use narrow and wide.

In print

The queries are screen-only. Printed, the page box (about 42 rem on A4 or Letter) would otherwise pick the mobile variant, so print always shows the desktop variant and hides the mobile one. Use data-print-only / data-screen-only for content that differs between screen and paper.

Container Variants

narrow and wide measure the nearest query container above the element, so the same markup can sit in a sidebar and in the main column and show the variant that fits each.

  • Which box is measured. <main>, <article>, <section> and <aside> are query containers already. Add data-container to make any other element one. The element is measured against its nearest container ancestor, never against itself.
  • The threshold is 30 rem, the width the layouts already switch at (the m threshold of <layout-switcher>). For another width write your own @container rule.
  • No container, no hiding. With no query container above the element neither rule matches and both variants show. Some layouts turn a semantic child's container off so it can size to its content (the children of a cluster or a reel, for example); there the next container out is the one measured.
  • Same strength. These rules sit in the same reset layer with !important, so they win in the same way as the viewport values.
  • One value per element. data-visible holds a single value. To combine a viewport and a container condition, nest two elements.

Desktop-Only Content

Use data-visible="desktop" on elements that should disappear on narrow viewports:

Mobile-Only Content

Use data-visible="mobile" on elements that should only appear on narrow viewports:

Responsive Nav Pattern

The most common use case: toggle between a horizontal desktop nav and a hamburger + bottom tab bar on mobile. No custom media queries needed.

See the responsive nav demo for a full working example.

Values

Value Visible Hidden
desktop ≥ 48 rem < 48 rem
mobile < 48 rem ≥ 48 rem
wide Container ≥ 30 rem Container < 30 rem
narrow Container < 30 rem Container ≥ 30 rem

Accessibility

  • Elements hidden with display: none are removed from the accessibility tree — screen readers will not announce them
  • Ensure equivalent content is available at both breakpoints; hiding a desktop nav is fine when a mobile nav provides the same links
  • Do not use data-visible to hide content that has no mobile equivalent — that would reduce accessibility on narrow screens
  • The hamburger button should include an aria-label since it typically contains only an icon
  • At 400% zoom a 1280 px desktop is about 20 rem wide, so zoomed-in users get the mobile variant. Keep the two variants equivalent so nothing is lost on reflow (WCAG 1.4.10)

Related

  • data-container — makes an element a query container, the box narrow and wide measure.
  • data-print — data-print-only, data-no-print and data-screen-only for screen vs paper.
  • hide-until-ready — hiding until a component is defined, not by width.
  • <mobile-menu> — a complete responsive navigation that switches at its own breakpoint.
  • hidden — the native attribute; it shares the same reset-layer mechanism.
↑