Responsive
Breakpoints
| Breakpoint | Width | At or below | Above |
|---|---|---|---|
xxs | 480px | — | — |
xs | 576px | xs: (max-width: 576px) | gtXs: (min-width: 577px) |
sm | 768px | sm: (max-width: 768px) | gtSm: (min-width: 769px) |
md | 992px | md: (max-width: 992px) | gtMd: (min-width: 993px) |
lg | 1200px | lg: (max-width: 1200px) | gtLg: (min-width: 1201px) |
xl | 1408px | xl: (max-width: 1408px) | gtXl: (min-width: 1409px) |
xxl | 1920px | — | — |
They come from the config, so createTheme({ breakpoints })
rebuilds the media queries and every consumer follows.
Media clauses
A breakpoint is a modifier inside the value of the property it changes:
<Box p="sm gtMd:lg" flexDirection="column gtSm:row" display="none gtXs:flex" />Two families come from the config:
xs:…xl:match at or below that breakpoint (max-width);gtXs:…gtXl:match above it (min-width).
So a mobile-first value reads as "base, then gt…: overrides as the viewport
grows". When the base or a breakpoint value is computed, use the object form:
<Box p={{ default: compact ? "xs" : "sm", gtMd: "lg" }} />Clause order does not matter, and state clauses (hover:, press:, focus:,
disabled:) outrank media clauses. v2's media props ($sm={{ … }},
$gtMd={{ … }}) are gone.
Container queries work the same way against the nearest element marked
container: w="100% @sm:50%".
In JavaScript
import { useMedia } from "@knitui/core";
function Nav() {
const media = useMedia();
return media.gtSm ? <Sidebar /> : <Drawer />;
}useMedia is reactive on both platforms — on native it tracks the window
dimensions, on the web it uses matchMedia.
SSR-safe queries
Server rendering has no viewport, so a naive matchMedia read produces a
hydration mismatch. @knitui/mediaquery exists for
that case:
import { MediaQueryProvider, useMediaQuery } from "@knitui/mediaquery";
// seed from the request's user agent so the first paint is close
<MediaQueryProvider userAgent={headers().get("user-agent")}>const isWide = useMediaQuery("(min-width: 992px)");On native it parses the query and answers from Dimensions, so the same call
works on device.
Viewport and element size
import { useElementSize, useViewportSize } from "@knitui/hooks";useViewportSize— window dimensions, both platforms.useElementSize— an element's measured box.
Orientation and platform
import { useOs } from "@knitui/hooks";
const os = useOs(); // "ios" | "android" | "macos" | "windows" | "linux" | "web" | undefinedUse it for genuine platform affordances (keyboard hints, store links), not for layout — layout should follow size, not OS.