DEV Community

suin
suin

Posted on

12 2 1 1 1

Visualize responsive breakpoint with TailwindCSS

When I was writing a responsive template using TailwindCSS, I felt that it is not easy to know which breakpoint is active.

So I made a simple component that visualizes which breakpoint is active. The following snippet is the implementation of the component:



<div class="fixed top-0 right-0 m-8 p-3 text-xs font-mono text-white h-6 w-6 rounded-full flex items-center justify-center bg-gray-700 sm:bg-pink-500 md:bg-orange-500 lg:bg-green-500 xl:bg-blue-500">
  <div class="block  sm:hidden md:hidden lg:hidden xl:hidden">al</div>
  <div class="hidden sm:block  md:hidden lg:hidden xl:hidden">sm</div>
  <div class="hidden sm:hidden md:block  lg:hidden xl:hidden">md</div>
  <div class="hidden sm:hidden md:hidden lg:block  xl:hidden">lg</div>
  <div class="hidden sm:hidden md:hidden lg:hidden xl:block">xl</div>
</div>


Enter fullscreen mode Exit fullscreen mode

Copying this and pasting to your TailwindCSS template, you will see the indicator of the breakpoint on top right in your browser.

Also, you can check the live demo at CodePen.

See the Pen Tailwind CSS Responsive Active Breakpoint Indicator by suin (@suin) on CodePen.

Billboard image

Monitoring as code

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (4)

Collapse
 
elvarp profile image
ElvarP

updated to include 2xl support:

<div class="fixed top-0 right-0 flex items-center justify-center w-6 h-6 p-3 m-8 font-mono text-xs text-white bg-gray-700 rounded-full sm:bg-pink-500 md:bg-orange-500 lg:bg-green-500 xl:bg-blue-500 2xl:bg-purple-500">
    <div class="block sm:hidden md:hidden lg:hidden xl:hidden">al</div>
    <div class="hidden sm:block md:hidden lg:hidden xl:hidden">sm</div>
    <div class="hidden sm:hidden md:block lg:hidden xl:hidden">md</div>
    <div class="hidden sm:hidden md:hidden lg:block xl:hidden">lg</div>
    <div class="hidden sm:hidden md:hidden lg:hidden xl:block 2xl:hidden">xl</div>
    <div class="hidden sm:hidden md:hidden lg:hidden xl:hidden 2xl:block">2xl</div>
</div>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
dakira profile image
Matthias Niess • Edited

I used this so many times now. Just wanted to leave you a big thank you. It's easy to write this, but it's even easier to just google tailwind breakpoints every time I need this. :)

Collapse
 
mfatica profile image
Marco Fatica

mine shows only "al" at all sizes, do you know what's wrong?

Collapse
 
mfatica profile image
Marco Fatica

nevermind i found the answer, my page was zoomed

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay