Skip to main content

Breakpoints

Responsive breakpoints for building adaptive layouts.

Live demo

Current breakpoint

Current breakpoint:default

Below extra extra small?

Below 2xs (360px):false

Below extra small?

Below xs (480px):false

Below small?

Below sm (640px):false

Below medium?

Below md (768px):false

Below large?

Below lg (1024px):false

Resize your browser window to see the values change in real-time.

Breakpoint values

Mantle has seven breakpoints. The default row is the unprefixed base, which applies at every width:

Breakpoint prefixMinimum widthCSS
default0rem (0px)No media query
2xs22.5rem (360px)@media (width >= 22.5rem) { ... }
xs30rem (480px)@media (width >= 30rem) { ... }
sm40rem (640px)@media (width >= 40rem) { ... }
md48rem (768px)@media (width >= 48rem) { ... }
lg64rem (1024px)@media (width >= 64rem) { ... }
xl80rem (1280px)@media (width >= 80rem) { ... }
2xl96rem (1536px)@media (width >= 96rem) { ... }

xs (480px) is wider than most phones, so a class with only an xs: value applies nothing on a phone. Give an unprefixed base value first, then override it at the breakpoint: flex-col xs:flex-row.

Minimum supported width

Design for a viewport 320px (20rem) wide and wider. This floor applies to mantle, the docs and marketing sites, and the ngrok app.

At 320px, the page doesn't scroll sideways and no content is cut off. A table, a code block, or a tab list can scroll inside its own box. Below 320px, a layout problem isn't a bug.

320px is the width that WCAG 2.2 Reflow (1.4.10) requires: a 1280px window zoomed to 400%.

The unprefixed styles cover every width below 2xs (360px), so check them at 320px, not at a typical phone width.

useBreakpoint hook

The useBreakpoint hook returns the largest breakpoint that the viewport width matches.

import { useBreakpoint } from "@ngrok/mantle/hooks"; function ResponsiveComponent() {	const breakpoint = useBreakpoint(); 	return (		<div>			<p>Current breakpoint: {breakpoint}</p>			{breakpoint === "lg" && <p>This shows only at the lg breakpoint.</p>}		</div>	);}

Every caller shares one app-wide subscription to the breakpoint media queries. On the server and during hydration, the hook returns "default". After hydration, it returns the breakpoint of the viewport.

Return value

A Breakpoint: "default", "2xs", "xs", "sm", "md", "lg", "xl", or "2xl".

useIsBelowBreakpoint hook

The useIsBelowBreakpoint hook returns true while the viewport is narrower than the given breakpoint. On the server and during hydration, it returns false.

import { useIsBelowBreakpoint } from "@ngrok/mantle/hooks"; function ResponsiveSidebar() {	const isMobile = useIsBelowBreakpoint("md"); 	return <aside>{isMobile ? <MobileNav /> : <DesktopNav />}</aside>;}

Parameters

A TailwindBreakpoint: "2xs", "xs", "sm", "md", "lg", "xl", or "2xl".

Hooks or classes

Use a hook when the component tree changes at a breakpoint, as in the sidebar above. For a style change, use a breakpoint class such as md:hidden. CSS applies at first paint. A hook value changes only after hydration, so in a server-rendered app a phone first shows the desktop layout.