Stop Rebuilding UI

Shadcn.io is not affiliated with official shadcn/ui

React useMediaQuery Hook

React useMediaQuery hook for responsive breakpoints and CSS media queries. Live updates, SSR safe, TypeScript ready.

Respond to CSS media queries in React. useMediaQuery takes a query string and returns true when it matches, false otherwise. Updates live when viewport changes or system preferences update. Uses matchMedia API with Safari legacy support. Configurable default value for SSR. Perfect for responsive layouts, dark mode detection, reduced motion, print styles, or any CSS media feature. No CSS-in-JS required—works with any styling approach. SSR safe with defaultValue option. Works with Next.js App Router, Tailwind CSS breakpoints, and any React framework.

React useMediaQuery Hook preview

Scroll to load preview

Installation

FAQ

Was this page helpful?

Sign in to leave feedback.