Knit UI
GitHub

Responsive

Breakpoints

BreakpointWidthAt or belowAbove
xxs480px——
xs576pxxs: (max-width: 576px)gtXs: (min-width: 577px)
sm768pxsm: (max-width: 768px)gtSm: (min-width: 769px)
md992pxmd: (max-width: 992px)gtMd: (min-width: 993px)
lg1200pxlg: (max-width: 1200px)gtLg: (min-width: 1201px)
xl1408pxxl: (max-width: 1408px)gtXl: (min-width: 1409px)
xxl1920px——

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";

Orientation and platform

import { useOs } from "@knitui/hooks";

const os = useOs(); // "ios" | "android" | "macos" | "windows" | "linux" | "web" | undefined

Use it for genuine platform affordances (keyboard hints, store links), not for layout — layout should follow size, not OS.

Edit this page on GitHub