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.

Retry later

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

Retry later
👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay