Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

useIsMobile

Reports whether the viewport is below the mobile breakpoint.

useIsMobile tells you if the viewport is less than 768px. It uses matchMedia, so it reacts instantly to browser zoom and device rotation, not just window resizing.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/use-is-mobile.json

Usage

import { useIsMobile } from "@/registry/react/hooks/use-is-mobile";

Example

"use client";

import { useIsMobile } from "@/registry/react/hooks/use-is-mobile";

export function Example() {
  const isMobile = useIsMobile();

  return (
    <p className="text-muted-foreground text-sm">
      {isMobile ? "Mobile layout" : "Desktop layout"}
    </p>
  );
}