data-visible
Responsive visibility utility. Show or hide elements based on viewport width without writing custom media queries.
Overview
The data-visible attribute controls element visibility based on viewport width. It eliminates the need for custom @media queries when toggling between desktop and mobile layouts.
data-visible="desktop"— visible at 48 rem and above, hidden belowdata-visible="mobile"— visible below 48 rem, hidden at 48 rem and above
The breakpoint (48 rem) corresponds to a typical tablet/desktop threshold. Because the rules live in the utils cascade layer, they override styles from earlier layers (tokens, reset, native-elements, custom-elements, web-components) without needing !important.
How It Works
Two media queries set display: none 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.
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 |
Accessibility
- Elements hidden with
display: noneare 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-visibleto hide content that has no mobile equivalent — that would reduce accessibility on narrow screens - The hamburger button should include an
aria-labelsince it typically contains only an icon