Snippet

Tailwind Indicator

A breakpoint indicator that shows the current screen size.

Credit

This component comes from the shadcn/ui library source code.

Demo

Resize the window to see the indicator change.


Usage

src/app/layout.tsx
import { TailwindIndicator } from '@/components/tailwind-indicator'
 
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
  return (
    <html lang='en'>
      <body>
        <main>{children}</main>
        <TailwindIndicator />
      </body>
    </html>
  )
}

Source Code

src/components/tailwind-indicator.tsx
export function TailwindIndicator() {
  if (process.env.NODE_ENV === 'production') return null
 
  return (
    <div className='fixed bottom-1 left-1 z-50 flex size-6 items-center justify-center rounded-full bg-background p-3 font-mono text-xs text-foreground'>
      <div className='block sm:hidden'>xs</div>
      <div className='hidden sm:block md:hidden'>sm</div>
      <div className='hidden md:block lg:hidden'>md</div>
      <div className='hidden lg:block xl:hidden'>lg</div>
      <div className='hidden xl:block 2xl:hidden'>xl</div>
      <div className='hidden 2xl:block'>2xl</div>
    </div>
  )
}